Original Post
I've been working mainly in Windows with VC11, but a few days ago switched to using MinGW (I had already been planning on switching, I just liked Visual Studio's plugins too much). Very quickly, I then installed GCC/G++ 4.7 on my Linux (Mint). Making a launcher executable for my library (This makes it easier for separation, or changing which library is launched without recompiling a large amount of code), I use Boost.Extension's shared_library (which simply uses LoadLibrary and dlopen (depending on the platform)) to load my dynamic/shared library (SFGame.so). This worked great on windows with both compilers, but on Linux, dlopen will fail however I use the path. Using the same path, Boost.Filesystem confirms (through the application) that the file can be accessed with the paths I'm using. My simple code: ("<" and ">" replaced with "^")
[source lang="cpp"]#include "iostream"
#include "functional"
#include "boost/extension/shared_library.hpp"
#include "boost/filesystem.hpp"
#if _WIN32 || _WIN64
# define EXT ".dll"
#elif __APPLE__
# define EXT ".dylib"
#elif __linux
# define EXT ".so"
#endif
int main( void )
{
using namespace boost::extensions;
using namespace boost::filesystem;
std::string libpath = "./SFGame.so";
path pfile( libpath );
if( exists( pfile ) )
{
std::cout ^^ "Game library: " ^^ complete( pfile ).generic_string() ^^ " exists\nSize: " ^^ file_size( pfile ) ^^ "\n";
}
shared_library lib( libpath );
if( !lib.open() )
{
std::cout ^^ "Failed to load " ^^ libpath ^^ "\n" ^^ dlerror() ^^ "\n";
return 0;
}
lib.get^void^( "Launch" )();
return 1;
}[/source]
This same code works perfectly on Windows, as I said. My output:
../../BinLinux//SFGame.so: cannot open shared object library
or:
SFGame.so: cannot open shared object library
depending on whether I use "./SFGame.so" (I assume because my Code::Blocks project file and main.cpp are in "Engine/Code/Game/" and SFGame.so is in "Engine/BinLinux/") or "SFGame.so". I can use the full path from "complete(pfile).generic_string()", which gives the same dir in the error as "./SFGame.so". Any ideas on how I could fix this from failing EVERY time? I even tried linking Launcher to Engine.so in the compiler (GNU GCC (well, g++) within Code::Blocks), but no dice.
[source lang="cpp"]#include "iostream"
#include "functional"
#include "boost/extension/shared_library.hpp"
#include "boost/filesystem.hpp"
#if _WIN32 || _WIN64
# define EXT ".dll"
#elif __APPLE__
# define EXT ".dylib"
#elif __linux
# define EXT ".so"
#endif
int main( void )
{
using namespace boost::extensions;
using namespace boost::filesystem;
std::string libpath = "./SFGame.so";
path pfile( libpath );
if( exists( pfile ) )
{
std::cout ^^ "Game library: " ^^ complete( pfile ).generic_string() ^^ " exists\nSize: " ^^ file_size( pfile ) ^^ "\n";
}
shared_library lib( libpath );
if( !lib.open() )
{
std::cout ^^ "Failed to load " ^^ libpath ^^ "\n" ^^ dlerror() ^^ "\n";
return 0;
}
lib.get^void^( "Launch" )();
return 1;
}[/source]
This same code works perfectly on Windows, as I said. My output:
../../BinLinux//SFGame.so: cannot open shared object library
or:
SFGame.so: cannot open shared object library
depending on whether I use "./SFGame.so" (I assume because my Code::Blocks project file and main.cpp are in "Engine/Code/Game/" and SFGame.so is in "Engine/BinLinux/") or "SFGame.so". I can use the full path from "complete(pfile).generic_string()", which gives the same dir in the error as "./SFGame.so". Any ideas on how I could fix this from failing EVERY time? I even tried linking Launcher to Engine.so in the compiler (GNU GCC (well, g++) within Code::Blocks), but no dice.