简体   繁体   中英

including libcurl in CMake Env

I use a Cmake build env, which generates Make files. I wanted to include libcurl library as I am getting a link error with curl APIs. Where to include libcurl library for static linking.


Build error Log:

Linking C executable lwm2mclient
CMakeFiles/lwm2mclient.dir/core/objects.c.o: In function 'lwm2m_imp_actuate1':
objects.c:(.text+0x95): undefined reference to 'curl_global_init'
objects.c:(.text+0x9a): undefined reference to 'curl_easy_init'
objects.c:(.text+0xbd): undefined reference to 'curl_easy_setopt'
objects.c:(.text+0xd5): undefined reference to 'curl_easy_setopt'
objects.c:(.text+0xde): undefined reference to 'curl_easy_perform'
objects.c:(.text+0xef): undefined reference to 'curl_easy_strerror'
objects.c:(.text+0x111): undefined reference to 'curl_easy_cleanup'
objects.c:(.text+0x116): undefined reference to 'curl_global_cleanup'
collect2: ld returned 1 exit status

make[2]: *** [lwm2mclient] Error 1
make[1]: *** [CMakeFiles/lwm2mclient.dir/all] Error 2

In your cmake file(CMakelists.txt), you have to add a link_directories, for example:

 link_directories(your_libfile_directory) add_executable(executable_name file_c_cpp) target_link_libraries(executable_name curl) 

For more details: http://www.cmake.org/cmake-tutorial/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM