Having issues compiling C code (sqlite) libdl.so not linked

I have a project that includes sqlite3 code for basic db access.

all the rest compiles well, but sqlite3 code fails with the following:

CMakeFiles/tCPP.dir/src/sql3/sqlite3.c.o: In function `unixDlOpen':
/home/narunas/Development/todo/tCPP/src/sql3/sqlite3.c:28402: undefined reference to `dlopen'
CMakeFiles/tCPP.dir/src/sql3/sqlite3.c.o: In function `unixDlError':
/home/narunas/Development/todo/tCPP/src/sql3/sqlite3.c:28416: undefined reference to `dlerror'
CMakeFiles/tCPP.dir/src/sql3/sqlite3.c.o: In function `unixDlSym':
/home/narunas/Development/todo/tCPP/src/sql3/sqlite3.c:28442: undefined reference to `dlsym'
CMakeFiles/tCPP.dir/src/sql3/sqlite3.c.o: In function `unixDlClose':
/home/narunas/Development/todo/tCPP/src/sql3/sqlite3.c:28447: undefined reference to `dlclose'

my CMake includes the following paramaters:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -ldl -std=c++11 ")

it appears that the libdl.so is not linked or the flag "-ldl" is not passed

Could use some advice
Narunas

3 comments
Comment actions Permalink

just to simplify the above question:

including boilerplate start of new project code with a call to dlopen.
**main.cpp**

 
#include <iostream>
#include
<dlfcn.h>

using namespace std;

int
main() {
    cout << "Hello, World!" << endl;

    char
* file = (char*)"/path/to/file";
    
dlopen(file, RTLD_NOW);


    return 0;
}


** CMakeList.txt **

 
cmake_minimum_required(VERSION 3.1)
project(testDLopen)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ldl  -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(testDLopen ${SOURCE_FILES})


in CMake tab > Cache I also added the -ldl flag to "CMAKE_C_FLAGS"

the above fails to compile as in the original question.

0
Comment actions Permalink

Hi Narunas!

Please try the following CMakeLists.txt, it works for me:

cmake_minimum_required(VERSION 3.1)
project(testDLopen)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testDLopen ${SOURCE_FILES})
target_link_libraries(testDLopen ${CMAKE_DL_LIBS})

0
Comment actions Permalink

Thanks Anna - this appears to have solved the issue - the test program and the one that uses sqlite3 now compile!
Again, thanks!
Narunas

0

Please sign in to leave a comment.