0

I use CMake to built a static library with libcurl linked with it.

find_package(CURL REQUIRED)
if(CURL_FOUND)
    message(STATUS "curl found")
    include_directories(${CURL_INCLUDE_DIR})
    set(requiredlibs ${requiredlibs} ${CURL_LIBRARY})
else()
    message(FATAL_ERROR "CURL NOT FOUND")
endif(CURL_FOUND)

target_link_libraries(${LIB_NAME} ${CURL_LIBRARY})

Now I want to use this library in my other Qt Project. I did the following in the WindowsClient.pro file:

DEPENDPATH += "$$PWD/../../LIB_NAME/include"
INCLUDEPATH += "$$PWD/../../LIB_NAME/include"

Debug:LIBS += -L"$$PWD/../../LIB_NAME/build/Debug/" -lmyLib-d
Debug:PRE_TARGETDEPS += "$$PWD/../../LIB_NAME/build/Debug/myLib-d.lib"

Release:LIBS += -L"$$PWD/../../LIB_NAME/build/Release/" -lmyLib
Release:PRE_TARGETDEPS += "$$PWD/../../LIB_NAME/build/Release/myLib.lib"

The problem is when I'm trying to build my Qt Project, it always gives me linkage error:

myLib.lib(lib.obj):-1: error: LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall lib::fetchCompanyName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V34@@Z)

I've stuck on this problem forever...Thanks in advance!!!

Gaojie Li
  • 1
  • 2
  • Is libcurl a dynamic library? If so, you will have to link with it in your Qt project. – Anon Mail Sep 14 '17 at 18:55
  • No, I build libcurl as a static library. – Gaojie Li Sep 14 '17 at 19:09
  • It's not that easy. See this link among others: https://stackoverflow.com/questions/20985631/static-library-of-libcurl-on-windows – Anon Mail Sep 14 '17 at 21:11
  • The `if` statement in your CMake file is superfluous; The "REQUIRED" flag already generates an error message when libcurl isn't found. – Cubic Sep 14 '17 at 21:11
  • You're on Windows, right? Use Dependency Walker to analyze myLib as built by the CMake project. See if it depends on the libcurl functions. – MultipleMonomials Sep 15 '17 at 01:32
  • I checked it.. I don't think its included in the lib file. But I did everything in the CMake file, why it's not in the lib.. – Gaojie Li Sep 15 '17 at 20:52
  • If you use QtCreator add cmake path to Tools->Options->Build&Run->Cmake Make your lib again and link to new location – saeed Sep 16 '17 at 04:18
  • I did has an auto detected CMake.exe there.. And I've successfully linked the quickfix library and it works. Only curl part doesn't work.. – Gaojie Li Sep 18 '17 at 13:44

0 Answers0