1

If I try to build cURL it shows me the following output:

Checking Build System
  Building Custom Rule C:/CPP/Projects/WebsiteGuardian/CMakeLists.txt
LINK : warning LNK4098: Standardbibliothek "LIBCMTD" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Biblioth
ek verwenden. [C:\CPP\Projects\WebsiteGuardian\build\WebsiteGuardian.vcxproj]
  WebsiteGuardian.vcxproj -> C:\CPP\Projects\WebsiteGuardian\build\Debug\WebsiteGuardian.exe
  Building Custom Rule C:/CPP/Projects/WebsiteGuardian/CMakeLists.txt

I build it like this: I downloaded the current .zip from here: curl.haxx.se/download.html After that I build curl with: "Set RTLIBCFG=static" and "nmake /f Makefile.vc mode=static VC=15 MACHINE=x86 DEBUG=no". I copied the include- and lib directory in my projectfolder. It will also found succesfully. My CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(WebsiteGuardian CXX)

set(CMAKE_CXX_STANDARD 17)
set(CURL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
set(CURL_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libcurl_a_debug.lib )

add_definitions(-DCURL_STATICLIB)
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})

add_executable(WebsiteGuardian "src/main.cpp")
target_link_libraries(WebsiteGuardian ${CURL_LIBRARY} wldap32 ws2_32 Crypt32.lib Wldap32 Normaliz)
TheDummy
  • 71
  • 1
  • 6
  • No, it shows me the same output. – TheDummy Apr 01 '20 at 13:19
  • 1
    Welcome to Stack Overflow! Do you have curl installed? – Kevin Apr 01 '20 at 13:22
  • If you want to link with a library, which absolute path is specified in `CURL_LIBRARY` variable, just link against this path: `target_link_libraries(WebsiteGuardian ${CURL_LIBRARY})`. – Tsyvarev Apr 01 '20 at 13:23
  • thanks^^. I downloaded the current .zip from here: https://curl.haxx.se/download.html After that I build curl with: "Set RTLIBCFG=static" and "nmake /f Makefile.vc mode=static VC=15 MACHINE=x86 DEBUG=no". I copied the include- and lib directory in my projectfolder. It will also found succesfully: -- Found CURL: -lcurl (found version "7.69.1") – TheDummy Apr 01 '20 at 13:28
  • @Tsyvarev like this: target_link_libraries(WebsiteGuardian ${CURL_LIBRARY} wldap32 ws2_32) ? – TheDummy Apr 01 '20 at 13:31
  • @Tsyvarev It shows me that: https://pastebin.com/0vWabddx ^^ – TheDummy Apr 01 '20 at 13:39
  • Yes, you may list several libraries to link in one `target_link_libraries` command. Note, that for building the project under **MinGW** you need to use libraries built for MinGW too. The library built for **Visual Studio** isn't suited. – Tsyvarev Apr 01 '20 at 13:44
  • Oh, thanks @Tsyvarev. That is a good point. I changed it. Now I get this Errors (sry for german output) https://pastebin.com/d0u81L3Z . If I add set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB") so I get this errors: https://pastebin.com/jz1gTv1N – TheDummy Apr 01 '20 at 14:12
  • "I changed it." - **What exactly** you have changed? According to the logs (`LNKxxxx` errors), you are trying to build CMake project in **Visual Studio** instead of **MinGW**. You probably need to read [that answer](https://stackoverflow.com/questions/53861300/how-do-you-properly-install-libcurl-for-use-in-visual-studio-2017) about libraries required for use curl under Visual Studio. – Tsyvarev Apr 01 '20 at 15:31
  • "I changed it." ->I used VisualStudio as Generator for CMake. And I builded libcurl like your link. Only the steps in VisualStudio I left it out because I would use CMake instead of the VisualStudio-IDE. – TheDummy Apr 01 '20 at 15:47
  • Whether you use CMake or not, you still need to link with libraries specified in the step 8 of the [referenced answer](https://stackoverflow.com/questions/53861300/how-do-you-properly-install-libcurl-for-use-in-visual-studio-2017). If you still face with some errors, please, **update your question post** about that errors. – Tsyvarev Apr 01 '20 at 16:01
  • Ok. I updated my question-post. I got the same errors after adding the other libs. – TheDummy Apr 01 '20 at 16:49
  • Message `defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library` indicates that your library has been built with options **incompatible** with the one you use for the project, see e.g. [that question](https://stackoverflow.com/questions/14148933/libcmt-conflicts-with-use-of-other-libs-unresolved-external-symbols/14158187) or that: https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098?view=vs-2019. Adding `/NODEFAULTLIB` switch is not the right way for handle this incompatibility. – Tsyvarev Apr 01 '20 at 18:11
  • Please, update the question post with the code which does NOT use `/NODEFAULTLIB` switch and the error message corresponded to that code. Also, add to the question post description how have you built `libcurl`. Such description is important as you have incompatibility issues. (Yes, I see that description in the comments, but Stack Overflow **requires** all important information to be in the question post itself, not in the comments.) I don't quite understand the source of such incompatibility, but other readers may help you. – Tsyvarev Apr 01 '20 at 18:15

1 Answers1

2

Thanks for the many answers. This works fine for me:

cmake_minimum_required(VERSION 3.10)
project(WebsiteGuardian CXX)

set(CMAKE_CXX_STANDARD 17)
set(CURL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
set(CURL_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libcurl_a_debug.lib )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")

add_definitions(-DCURL_STATICLIB)

find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})

add_executable(WebsiteGuardian "src/main.cpp")
target_link_libraries(WebsiteGuardian ${CURL_LIBRARY} wldap32 ws2_32 Crypt32.lib Wldap32 Normaliz)
TheDummy
  • 71
  • 1
  • 6