1 (edited by Andids 2024-10-11 01:17:09)

Topic: libcurl not linking properly in vscode with msvc 2022

I'm trying to use libcurl in vscode with the MSVC 2022 compiler and linker but im getting a lot of linking errors. I am a noob so I probably did a dumb mistake.


I first built libcurl from source code using the x64 VS tools command prompt with the following command:

nmake /f Makefile.vc mode=static


I got a libcurl_a.lib file and some include headers so I added those to my project with the code:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <conio.h>

#include "curl\curl.h"


I then launched vscode from x64 VS tools and used the following command:

cl /std:c17 /Iinclude src/main.c /link /LIBPATH:lib geometry dash breeze


Instead of it giving me an exe, I got a bunch of unresolved external symbol errors and the obj file.


My libcurl_a.lib file is in the lib folder, all the headers are in the include\curl folder, and main.c is in the src folder.


Here's the output:

Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32822 for x64

Copyright (C) Microsoft Corporation. All rights reserved.


main.c

Microsoft (R) Incremental Linker Version 14.37.32822.0

Copyright (C) Microsoft Corporation. All rights reserved.


/out:main.exe

/LIBPATH:lib

main.obj

main.obj : error LNK2019: unresolved external symbol curl_global_init referenced in function main

main.obj : error LNK2019: unresolved external symbol curl_global_cleanup referenced in function main

main.obj : error LNK2019: unresolved external symbol curl_easy_init referenced in function main

main.obj : error LNK2019: unresolved external symbol curl_easy_cleanup referenced in function main

main.exe : fatal error LNK1120: 4 unresolved externals


I've tried putting #define CURL_STATICLIB and #pragma comment(lib, "lib\libcurl_a.lib") but those don't fix it either.

Share

Re: libcurl not linking properly in vscode with msvc 2022

Hi Andids

Welcome to the wolfSSL Forums.

Could you tell us a bit about your Curl project and your location for our support records?

Did you review the Cmake instructions?
https://github.com/curl/curl/blob/maste … L-CMAKE.md

Thanks,
Eric - wolfSSL Support