我使用Cmake构建env,它生成Make文件。我想包含libcurl库,因为我收到curl API的链接错误。哪里包含用于静态链接的libcurl库。
构建错误日志:
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
答案 0 :(得分:1)
在您的cmake文件(CMakelists.txt)中,您必须添加link_directories,例如:
link_directories(your_libfile_directory) add_executable(executable_name file_c_cpp) target_link_libraries(executable_name curl)