Boost-Filesystem statisch linken klappt nicht



  • Servus,

    ich kriege es nicht gebacken Filesystem von Boost bei meinem Miniprojekt statisch zu linken. Ich will, dass die ausführbare Datei dann auf dem anderen Computer auch läuft - beides sind Linux-Maschinen, ich denke da sollte es keine Probleme geben.

    Ich habe schon etwas rumgelesen und bin nicht der erste bei dem es in der Kombo Linux und Boost Filesystem harpert. Ich habe mal in meinen usr/lib/-Ordner geschaut und für boost liegen sowohl die .so wie auch die .a-Dateien im Ordner. Dazu kompiliert das Programm wenn ich das static weglasse ... das wundert mich. Danke vorab für einen Vorschag, hier noch der Link zum anderen Problemhaber: http://ubuntuforums.org/archive/index.php/t-897996.html

    Also Code des Snippets:

    #include <boost/filesystem.hpp>
    #include <boost/operators.hpp>
    
    #include <boost/random/mersenne_twister.hpp>
    #include <boost/random/uniform_int.hpp>
    #include <boost/random/variate_generator.hpp>
    #include <ctime>
    
    #include<iostream>
    #include <sstream>
    
    using namespace std;
    
        class Dice {
        public:
            Dice() : engine( std::time(0) ) { // Funktor-Einsatz
            };
            int operator()(int minIncluded, int maxIncluded) {
                return boost::uniform_int<int>(minIncluded, maxIncluded)(engine);
            }
        private:
            boost::mt19937 engine;
        };
    
        int getRandomInteger(Dice& dice, int minIncluded, int maxIncluded) {
            int ranInt = dice(minIncluded, maxIncluded);
            return ranInt;
        }
    
    int main( int argc, char* argv[] )
    {
    	Dice d;
    	cout << " Boost-Wuerfeln ... \n";
    
    	cout << " Wuerfe: " 
    		<< getRandomInteger(d, 1, 6) << "; "
    		<< getRandomInteger(d, 1, 6) << "; "
    		<< getRandomInteger(d, 1, 6) << "; ";
    
    		// Verzeichnis scripts anlegen
    		string s = "";
    		stringstream ss;
    		ss << argv[1];
    		s = ss.str();
                    string pathScriptsDir = "";
                    pathScriptsDir += s;
                    pathScriptsDir += "boosttest";
    
                    if ( boost::filesystem::exists( pathScriptsDir.c_str() ) )
                    {
                        cout << "| ... Verzeichnis " << pathScriptsDir << " existiert bereits!\n";
                    } else {
                        boost::filesystem::create_directory(pathScriptsDir.c_str());
                        cout << "| ... Verzeichnis " << pathScriptsDir << " angelegt.\n";
                    }
    
    }
    

    Das Kompilierkommando ist:
    g++ -o boostfullstatic -I/usr/include/boost/ -static -lboost_filesystem -lboost_system fullboost.cpp

    Fehlermeldung ist:
    Kompiliere ...
    /tmp/cc52baUy.o: In function \_\_static\_initialization\_and\_destruction_0(int, int)': fullboost.cpp:(.text+0x41b): undefined reference toboost::system::get_system_category()'
    fullboost.cpp:(.text+0x425): undefined reference to boost::system::get\_generic\_category()' fullboost.cpp:(.text+0x42f): undefined reference toboost::system::get_generic_category()'
    fullboost.cpp:(.text+0x439): undefined reference to boost::system::get\_generic\_category()' fullboost.cpp:(.text+0x443): undefined reference toboost::system::get_system_category()'
    /tmp/cc52baUy.o: In function boost::system::error\_code::error\_code()': fullboost.cpp:(.text.\_ZN5boost6system10error\_codeC1Ev[boost::system::error\_code::error\_code()]+0x10): undefined reference toboost::system::get_system_category()'
    /tmp/cc52baUy.o: In function boost::enable\_if<boost::filesystem::is\_basic\_path<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >(boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)': fullboost.cpp:(.text.\_ZN5boost10filesystem6existsINS0\_10basic\_pathISsNS0\_11path\_traitsEEEEENS\_9enable\_ifINS0\_13is\_basic\_pathIT\_EEbE4typeERKS7\_[boost::enable\_if<boost::filesystem::is\_basic\_path<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >(boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> const&)]+0x3d): undefined reference toboost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)'
    /tmp/cc52baUy.o: In function boost::enable\_if<boost::filesystem::is\_basic\_path<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >, bool>::type boost::filesystem::create\_directory<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >(boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> const&)': fullboost.cpp:(.text.\_ZN5boost10filesystem16create\_directoryINS0\_10basic\_pathISsNS0\_11path\_traitsEEEEENS\_9enable\_ifINS0\_13is\_basic\_pathIT\_EEbE4typeERKS7_[boost::enable\_if<boost::filesystem::is\_basic\_path<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >, bool>::type boost::filesystem::create\_directory<boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> >(boost::filesystem::basic\_path<std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >, boost::filesystem::path\_traits> const&)]+0x2b): undefined reference toboost::filesystem::detail::create_directory_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    collect2: ld returned 1 exit status
    Return: 256


  • Mod

    Hmm, funktioniert bei mir. Deine Fehlermeldungen sind aber genau die, die man bekommen würde, wenn man das -lboost_system weglassen würde. Daher vermute ich einen Fehler bei der Bedienung deinerseits.



  • Ah, manchmal kann es so einfach sein, die Reihenfolge der Parameter spielt bei g++ eine Rolle ... so gings:
    g++ -o boostfullstatic fullboost.cpp -I/usr/include/boost/ -static -lboost_filesystem -lboost_system


  • Mod

    Die Reihenfolge spielt immer eine Rolle, das ist keine Eigenart des g++. Hinten stehen die Bibliotheken, die von den Bibliotheken weiter vorne gebraucht werden.


Anmelden zum Antworten