Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Fullpath or execution dir on widows/linux/mac[SOLVED]  (Read 28488 times)

0 Members and 1 Guest are viewing this topic.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Fullpath or execution dir on widows/linux/mac
« Reply #30 on: July 30, 2013, 07:38:35 pm »
I meant you need to print the line somewhere in your app or in a file or something. The code I provided you is console only since it printf() in the console. So when you doubleclick on it nothing visible happen

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #31 on: July 30, 2013, 08:10:13 pm »
Yup, but the way you said it i tought you want me to actualy double click on console application and see what happends :)

Anyway put Hiura code into my app
This is output from terminal when i start compiled and builded application with ./Swing Studio 0:
/home/xwm/Developing/Swing Studio 0.4.0/bin/Debug/Swing Studio 0  << my #define __linux
/home/xwm/Developing/Swing Studio 0.4.0/bin/Debug                            << Hiura code

This is output from IDE terminal when i start application from IDE:
/home/xwm/Developing/Swing Studio 0.4.0/bin/Debug/Swing Studio 0 << my #define __linux
/home/xwm/Developing/Swing Studio 0.4.0                                            << Hiura code

EDIT: Typed Hiura Name/Nick wrong. My appology
EDIT NO 2. It was Lo-X code
« Last Edit: July 30, 2013, 08:43:02 pm by wmbuRn »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #32 on: July 30, 2013, 08:19:46 pm »
No surprise if he doesn't show the resourcePath() implementation :P

wof, it's only 15 lines of code to get only one string... not that much!  ;D

@wmbuRn, as Lo-X said, you need to redirect the output to some file. Maybe it's easier with a simple shell script.

#!/bin/sh

echo `pwd` >> /tmp/wd
 

Or something in this spirit. Just make sure you have the right to write to /tmp/wd.

This is output from IDE terminal when i start application from IDE:
/home/xwm/Developing/Swing Studio 0.4.0/bin/Debug/Swing Studio 0 << my #define __linux
/home/xwm/Developing/Swing Studio 0.4.0                                            << Hilura code

Who is this Hilura guy?  >:(  ;)

Note that my code has not the same intention as yours. It's normal to have such difference.

However, you point out something important: during development, if you're using an IDE, you don't want to use a full path... because your IDE doesn't create the binary in the expected folder. (Well, on Mac we don't care about that with .app bundle.)

So it seems there would be another issue to provide a 'resourcePath()' or 'workindDirectory()' method in SFML..

SFML / OS X developer

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #33 on: July 30, 2013, 08:29:45 pm »
#include <unistd.h>
#include <iostream>

int main(int, char**) {
    char* pwd = getwd(NULL);
    std::cout << "Working directory: " << pwd;
    free(pwd);
    return 0;
}
 

Cant compile:

=== hiura test, Debug ===
warning: ‘char* getwd(char*)’ is deprecated (declared at /usr/include/i386-linux-gnu/bits/unistd.h:222) [-Wdeprecated-declarations]|
warning: null argument where non-null required (argument 1) [-Wnonnull]|
warning: ‘char* getwd(char*)’ is deprecated (declared at /usr/include/i386-linux-gnu/bits/unistd.h:222) [-Wdeprecated-declarations]|
error: ‘free’ was not declared in this scope|
=== Build finished: 1 errors, 3 warnings (0 minutes, 1 seconds) ===

Give me a minut or two to test another code

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #34 on: July 30, 2013, 08:33:14 pm »
Use getcwd instead (with Lo-X code above). I just saw in my man page
Quote
HISTORY

     The getwd() function appeared in 4.0BSD.

BUGS

     The getwd() function does not do sufficient error checking and is not
     able to return very long, but valid, paths.  It is provided for compati-
     bility.

But if it doesn't compile now, of what code were you talking about ???
SFML / OS X developer

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #35 on: July 30, 2013, 08:34:42 pm »
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv)
{
    char the_path[256];

    getcwd(the_path, 255);

    printf("%s\n", the_path);

    return 0;
}
 

My mistake again.
its Lo-x code i used in my application, and the one i posted results

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #36 on: July 30, 2013, 08:35:53 pm »
Well, my comment still holds : they don't share the same intention. It's normal to have such difference.
SFML / OS X developer

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #37 on: July 30, 2013, 08:40:30 pm »
Yes, i will test what you said in minute or two :)

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #38 on: July 30, 2013, 08:54:50 pm »
So what you want me to do with Lo-X code ?

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Fullpath or execution dir on widows/linux/mac
« Reply #39 on: July 30, 2013, 09:01:02 pm »
So what you want me to do with Lo-X code ?

I just wanted have more clues about the fact that when you double click on the executable it faild loading images (as if it does not find them).

I think the issue is just over me now, I really don't know what's happening. Your executable should really behave the same way when you click or comand it (if you havent changed something like a path or I don't know).

I keep looking for a possible cause on my linux but.. nothing

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Fullpath or execution dir on widows/linux/mac
« Reply #40 on: July 30, 2013, 09:24:40 pm »
Do you have a minimal code that reproduce the same bug ? 'Cause I have to install tuxGUI and compile everything, and given the time in France, it will be tomorrow =)

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #41 on: July 30, 2013, 09:28:48 pm »
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");

    // Load a background
    sf::Texture background;
   if (!background.loadFromFile("Data/cb.bmp"))
   {
  return -1;
   }

    // load a sprite to display
    sf::Sprite sprite;
    sprite.setTexture(background);

        // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event Event;
        while (window.pollEvent(Event))
        {
            // Close window : exit
            if (Event.type == sf::Event::Closed)
                window.close();
        }

        // Clear screen
        window.clear();

        // Draw the sprite
        window.draw(sprite);

        // Update the window
        window.display();
    }

    return EXIT_SUCCESS;
}
 
with cb.bmp being in "Data" folder. From terminal and from IDE it works, cant start application with double click on it. Nothing happends


EDIT: I could see only black screen on my app since i didnt have
// Draw the sprite
window.draw(sprite);
 

I have: gui.draw();  << since i use tgui :)
« Last Edit: July 30, 2013, 09:33:26 pm by wmbuRn »

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Fullpath or execution dir on widows/linux/mac
« Reply #42 on: July 30, 2013, 09:38:36 pm »
I just did that, I've got the image with editor, console and double clicking.

Perhaps it's a issue with you linux configuration or nautilus configuration.

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #43 on: July 30, 2013, 09:40:45 pm »
But the path to execution directory inside program will solve the problems i have with either linux or nautilus? [ i am using program pantheon-files]

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Fullpath or execution dir on widows/linux/mac
« Reply #44 on: July 30, 2013, 10:24:28 pm »
So back to beginning:

#ifdef __linux
#include <unistd.h>

std::string getexepath()
  {
  char result[ PATH_MAX ];
  ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
  return std::string( result, (count > 0) ? count : 0 );
  }
 
Anyone have an idea how to fixthis code to get output of folder where the application is started without application name?

 

anything