Jump to content

Shared lib libsteam_api.so loading question


codeape
 Share

Recommended Posts

Ok, I have experience with Linux development since before. Before I can run my Leadwerks C++ game from the command line I need to set LD_LIBRARY_PATH or add the the path to libstem_api.so in /etc/ld.so.conf.d/ or simply copy or link the lib to /usr/lib etc etc. or simply run the game from Code::Blocks.

 

So my questions:

 

How does this work if a game is deployed on steam. Handles steam the loading path setting to libstem_api.so?

 

If I want to sell my game outside steam can I get rid of the libstem_api.so dependency or do I need to set the path to libstem_api.so in some bootstrap script (one of several ideas)?

 

Thank you for all info I can get

Link to comment
Share on other sites

Thank you guppy.

 

bascially if you try to run a c++ project binary currently it will fail with

 

"mygame: error while loading shared libraries: libsteam_api.so: cannot open shared object file: No such file or directory"

 

now you can get around that by specifying LD_PATH=. mygame, but that is quite frankly ugly and inconvenient

 

So please in Project -> Build options -> Linker settings -> Other linker options put

 

-Wl,-rpath=.

 

 

( personally I use "-Wl,-rpath=sharedlibs/" to avoid causing clutter in the root dir but that's just me wink.png )

 

I have still some thoughts though.

 

-Wl,-rpath= is a good option while you develop. However, -rpath will Add a directory to the runtime library search path. So if you compiled it in lets say : /home/myaccount/src/myLeadwerksgame it would add exactly that path. Am I wrong here? So if you distribute this to someone and that person puts the game in home/someone/games/myLeadwerksgame the game would still look for libsteam_api.so in /home/myaccount/src/myLeadwerksgame which will not exist on the other persons machine. Right?

Link to comment
Share on other sites

Did you specify a relative path or an absolute one?

 

if you specify a relative path ( like . or sharedlibs/ ) and do

 

readelf -d myLeadwerksgame | grep -i rpath

 

it should still show it as relative, no?

 

In case it really doesn't work you could try using $ORIGIN, in order to specify that in code::blocks you need a bit of voodoo apparently;

-Wl,-rpath=\\$$$ORIGIN

 

you can make it a sub directory by changing appending /subdir/

 

Let me know how that works out for you smile.png

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Thanks again guppy.

 

Well I did that and this works:

 

./myGame 

 

This does not:

./src/git/leadwerks/branch/branch.debug
./src/git/leadwerks/branch/branch.debug: error while loading shared libraries: libsteam_api.so: cannot open shared object file: No such file or directory

 

I hope you see what I am doing ... being the devils advocate ... No one wants to end up with this on a released game.

Link to comment
Share on other sites

Hat off for mr Guppy ... thanks =)

 

I can confirm that $ORIGIN works. No problems loading libsteam_api.so using any path (like ./src/git/leadwerks/branch/branch.debug or ./branch/branch.debug)

 

However another thing that now show up is this :

./branch/branch.debug
Initializing OpenGL4 graphics driver...
OpenGL version 431
GLSL version 430
Device: AMD Radeon HD 5700 Series
Error: Failed to load texture "Materials/Common/bfn.tex"
Error: Required texture "Materials/Common/bfn.tex" is missing.
Loading map "/home/codeape/src/git/leadwerks/Maps/start.map"...
[s_API FAIL] SteamAPI_Init() failed; SteamAPI_IsSteamRunning() failed.
[s_API FAIL] SteamAPI_Init() failed; unable to locate a running instance of Steam, or a local steamclient.so.
Error: Failed to read file "/home/codeape/src/git/leadwerks/Maps/start.map".
Error: Failed to load shader "./Shaders/Misc/occlusionquery.shader".

 

So the paths to the game resources are not bullet prof. Hopefully this should easily be fixed with some path magic I have used before. However, I need to figure out where to plug it in though =)

 

Well I will post an update about that later on this week.

Link to comment
Share on other sites

It's fairly easy to fix the paths, old trick with a bit of Leadwerks flavor sprinkled on;

 

chdir(FileSystem::ExtractDir(argv[0]).c_str());

 

I've no idea if it works in windows tho, I'll leave that as an excercise for the reader ;)

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Now everythion works as expected:

~/src/git/leadwerks/branch> ./branch.debug
~/src/git/leadwerks/test> ../branch/branch.debug
~> ./src/git/leadwerks/branch/branch.debug

 

All paths starts the game with loaded libsteam_api.so and all resources (textures, shaders etc.) with no errors.

 

I added this to my Source/main.cpp:

 

@@ -93,6 +93,9 @@ int main(int argc,const char *argv[])
 }
#endif
 App* app = new App;
+#ifdef __linux__
+	 FileSystem::SetDir(FileSystem::ExtractDir(argv[0]));
+#endif
 if (app->Start())
 {
		 while (app->Loop()) {}

 

The code added is the ifdef __linux__ stuff ... to be precise.

 

Thank you again Guppy. Awesome teamwork =)

Link to comment
Share on other sites

Extending resource file path fix to windows (it had the same problem)

 

#ifdef __linux__
FileSystem::SetDir(FileSystem::ExtractDir(argv[0]));
#else
HMODULE hModule = GetModuleHandle(NULL);
if (hModule != NULL) {
 char exePth[MAX_PATH];
 GetModuleFileName(hModule, exePth, MAX_PATH);
 FileSystem::SetDir(FileSystem::ExtractDir(exePth));
}
#endif

  • Upvote 1
Link to comment
Share on other sites

Hello MoustafaChamli

 

post-7525-0-04345200-1410209646_thumb.png

 

Ok so you must pick the top of the tree in the Project -> Build options -> Linker settings tree so you target both debug and release (it has the project name ... in my case branch). You must add the flags to

"Other linker options" ... see the red markings I made in the image.

 

Be sure to recompile the whole project!

Link to comment
Share on other sites

Hello codeape,

 

Thanks for the response!

Screenshot-09082014-091826-PM.png

 

 

It doesn't seem to work here, even after recompiling the full project and updating the project files.

 

This might be relevant, but Leadwerk had generated an ifdef __linux__, my main.cpp currentl has these lines:

#ifdef __linux__
   FileSystem::SetDir(FileSystem::ExtractDir(argv[0]));
#else
HMODULE hModule = GetModuleHandle(NULL);
if (hModule !=NULL) {
   char exePth[MAX_PATH];
   GetModuleFileName(hModule, exePth, MAX_PATH0);
   FileSystem::SetDir(FileSystem::ExtractDir(exePth))
}
#endif
#ifdef __linux__
#ifndef __ANDROID__
 settingsdir = settingsdir + "/." + String::Lower(settingsfile);
#else
 settingsdir = settingsdir + "/" + settingsfile;
#endif
#else
settingsdir = settingsdir + "/" + settingsfile;
#endif

 

 

Maybe that's not helping the compilation?

 

I can see libsteam_api.so in the project's root directory, so it's definitely not a case of a missing file.

 

Any ideas?

Link to comment
Share on other sites

Hello, sorry for the long reply.

 

I did actually rebuild. This is what the command outputs:

0x000000000000000f (RPATH)			 Library rpath: [$ORIGIN]

 

In that case there remains two possible error causes;

  1. libsteam_api.so is NOT in the same directory as your executable ( or is broken, try replacing it with the with one from a fresh project )
  2. Your missreading the error and what you see is just the "no running steam instance found" message

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

It turns out libsteam_api.so isn't copied into the directory when I build the project, which is a bit of an annoyance. But it seems to work when I copy libsteam_api.so to the published project's root directory.

 

Try to update your project with the in editor tool project manager. It should add the correct libsteam_api.so file. I had the same problem.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...