0

I'm noob at C and cmake and experience difficulties with a lib linkage. I have the following cmake:

cmake_minimum_required(VERSION 3.10)
project(EC C)

set(CMAKE_C_STANDARD 11)

add_executable(EC main.c)

set(CURL_INCLUDE_DIR C:/curl-8.14.1_1-win64-mingw/include)
set(CURL_LIBRARY C:/curl-8.14.1_1-win64-mingw/lib/libcurl.a)

find_package(CURL REQUIRED)
if(CURL_FOUND)
    message(STATUS "libcurl found")
    include_directories(${CURL_INCLUDE_DIRS})
    target_link_libraries(EC CURL::libcurl)
else()
    message(FATAL_ERROR "libcurl not found")
endif()

While building I receive like this:

C:/Users/DELL/CLionProjects/EC/main.c:22:(.text+0x118): undefined reference to `__imp_curl_easy_init'

As I understood I have a problem with static lib linkage, but can't find workable solution for me. How can I define what a lib is not linked and how to link it?

P.S. I've add add_compile_definitions(CURL_STATICLIB) to the end of cmake as n. m. could be an AI suggests, but get then new warnings like:

undefined reference to `__imp_closesocket`
6
  • You must have CURL_STATICLIB preprocessor macro defined. You can add it by adding add_compile_definitions(CURL_STATICLIB) to CMakeLists.txt. Commented Jun 11 at 19:17
  • This question is similar to: Unresolved symbols when linking a program using libcurl. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jun 12 at 2:11
  • @n. m. could be an AI thank you for the tip, but I get then many errors likeC:/curl-8.14.1_1-win64-mingw/lib/libcurl.a(unity_0_c.c.obj):unity_0_c.c:(.text$async_thrdd_destroy[async_thrdd_destroy]+0x13e): undefined reference to __imp_closesocket'` Commented Jun 12 at 8:48
  • You will need to add other libraries, like ws2_32 or wsock32 (where the socket functions are), and then probably some more (for encryption and whatnot). Commented Jun 12 at 9:50
  • 1
    "how can I define" By looking it up. I don't know of a better way. "should i link the lib to the project or lib to lib" You can link a DLL or an executable, but not a static library. Commented Jun 12 at 10:43

1 Answer 1

0

Try Install mingw64 or mingw32. And Use The Compiler Why? Because curl That You Using Is Compiled Using mingw Compiler.

Sign up to request clarification or add additional context in comments.

6 Comments

Can you verify that those products contain the necessary library?
Yes Like Win32 and other That Only Exsist On Windows.
The issue is to document specifically the __imp_closesocket interface.
__imp_closesocket is part of winsocket Api and the function use this is closesocket function that return int WSAAPI
So that should be your answer rather than what you have now.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.