Problem beim linken



  • #include <iostream>
    #include <sqlite3.h>
    #include <vector>
    #include <string>
    #include <boost/foreach.hpp>
    
    void sqlite_error( int num, char** msg );
    int callback( void*, int, char**, char** );
    
    int main() {
    
    	sqlite3 * db;
    	int rc;
    	char** msg;
    	std::vector<std::string> data;
    
    	if (( rc = sqlite3_open( "/home/lotos/projects/walletwatch/data/db.sqlite3", &db ) ) != SQLITE_OK ) {
    		if (( rc = sqlite3_exec( db, "SELECT * FROM category", &callback, &data, msg ) ) != SQLITE_OK ) {
    		    BOOST_FOREACH(std::string str, data) {
    		        std::cout << str << std::endl;
    		    }
    		}
    		else {
    		    sqlite_error(rc, msg);
    		}
    	} else {
    		sqlite_error( rc, 0 );
    		sqlite3_close( db );
    		return EXIT_FAILURE;
    	}
    
    	sqlite3_close( db );
    	return EXIT_SUCCESS;
    }
    
    void sqlite_error( int num, char** msg ) {
    
    	std::cerr << "SQLITE3: " << num << std::endl;
    	if ( msg != 0 ) {
    		std::cerr << *msg << std::endl;
    	}
    }
    
    int callback( void* vec, int field_count, char** field_values, char** column_names ) {
    
    	static_cast<std::vector<std::string>*>( vec ) -> push_back( std::string( field_values[field_count] ) );
    	return EXIT_SUCCESS;
    }
    

    Ich habe mir dieses kleine Testprogramm geschrieben, doch ich scheitere am linken.

    -------------- Build: Debug in sqlite3test ---------------
    
    Linking console executable: bin/Debug/sqlite3test
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexTry':
    (.text+0x136ee): undefined reference to `pthread_mutex_trylock'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':
    (.text+0x137ef): undefined reference to `pthread_mutexattr_init'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':
    (.text+0x137ff): undefined reference to `pthread_mutexattr_settype'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':
    (.text+0x13813): undefined reference to `pthread_mutexattr_destroy'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `unixDlError':
    (.text+0x14678): undefined reference to `dlerror'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `findLockInfo':
    (.text+0x65bc3): undefined reference to `pthread_create'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `findLockInfo':
    (.text+0x65bd6): undefined reference to `pthread_join'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `unixDlSym':
    (.text+0x1921): undefined reference to `dlsym'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `unixDlClose':
    (.text+0x1465b): undefined reference to `dlclose'
    ../../../../usr/lib/libsqlite3.a(sqlite3.o): In function `unixDlOpen':
    (.text+0x146c2): undefined reference to `dlopen'
    collect2: ld gab 1 als Ende-Status zurück
    Process terminated with status 1 (0 minutes, 0 seconds)
    10 errors, 0 warnings
    

    Ich benutze die Code::Blocks IDE auf Ubuntu 9.04 und habe bei unter Project > Build > Linkersettings libsqlite3.a hinzugefügt. Es gibt aber auch noch unter Project > Properties > Libraries die Möglichkeit, in pkg-config bekannte Bibliotheken dem Projekt hinzuzufügen.

    Das Problem ist also vermutlich, dass ich das "linken unter Linux" noch nicht so recht verstanden hab. Kann mich da jemand bitte aufklären?



  • fällt keinem was ein?



  • Du mußt dem Linker noch "-ldl -lpthread" mitgeben. Der erste Buchstabe ist jeweils ein kleines L.


Anmelden zum Antworten