www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Missing library dependencies compiling app with importC

reply ptcute <peterhu.peterhu outlook.com> writes:
Greeings!

My c to d header wrapper file curl_d.c (just 2 lines):

#include <curl/curl.h>
#include <windows.h> //seems with or without this doesn't matter

Trying A:  My main c file :direct_call_c.c:

#include <stdio.h>
#include <string.h>

#include "curl_d.c"

{...}

dmd -m64 direct_call_c.c curl_d.c curl.lib
... direct_call_c.obj : error LNK2019: 无法解析的外部符号 _InterlockedExchangeAdd,函数 _InlineInterlockedAdd 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 _InterlockedExchangeAdd64,函数 _InlineInterlockedAdd64 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 _mul128,函数 MultiplyExtract128 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 __shiftright128,函数 MultiplyExtract128 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 _umul128,函数 UnsignedMultiplyExtract128 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 __stosb,函数 RtlSecureZeroMemory 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 __readgsqword,函数 NtCurrentTeb 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 __imp_MapViewOfFileNuma2,函数 MapViewOfFile2 中引用了该符号 direct_call_c.obj : error LNK2019: 无法解析的外部符号 __imp_CharUpperW,函数 ua_CharUpperW 中引用了该符号 direct_call_c.exe : fatal error LNK1120: 9 个无法解析的外部命令 Error: linker exited with status 1120 Which means unsolved external symbos _InterlockedExchangeAA... Trying B: D code test01.d: import core.stdc.stdio; import curl_d; {...}
dmd -m64 test01.d curl_d.c curl.lib
Exact the same error message when compiling. The same c code in pure c using msvc/gcc is just fine with providing only curl.lib,compiles and runs as expected. In D here,what I was missing to provide?I tried to add many many windows libs like winspool.lib ws2_32.lib wsock32.lib websocket.lib advapi32.lib advpack.lib crypt32.lib icm32.lib icu.lib iepmapi.lib httpapi.lib kernel32.lib mapi32.lib mi.lib mincore.lib mmc.lib msi.lib msxml6.lib normaliz.lib nt.lib ntdll.lib winhttp.lib wininet.lib wiaguid.lib wer.lib wecapi.lib webauthn.lib vssapi.lib wldap32.lib wmip.lib wmiutils.lib wsnmp32.lib wtsapi32.lib,even ucrt.lib .... but it doesn't make any sense. So what's the real issue behind? Anyone help on this would be appreciated.
Feb 21
next sibling parent reply Danny Arends <Danny.Arends gmail.com> writes:
On Thursday, 22 February 2024 at 01:23:36 UTC, ptcute wrote:
 Greeings!

 My c to d header wrapper file curl_d.c (just 2 lines):
 ...
 So what's the real issue behind?

 Anyone help on this would be appreciated.
According to the windows documentation, you'll need: Kernel32.lib See: https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-interlockedexchange
Feb 22
parent reply ptcute <peterhu.peterhu outlook.com> writes:
On Thursday, 22 February 2024 at 13:24:45 UTC, Danny Arends wrote:
 On Thursday, 22 February 2024 at 01:23:36 UTC, ptcute wrote:
 Greeings!

 My c to d header wrapper file curl_d.c (just 2 lines):
 ...
 So what's the real issue behind?

 Anyone help on this would be appreciated.
According to the windows documentation, you'll need: Kernel32.lib See: https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-interlockedexchange
Thanks a lot for the help.But for Kernel32.lib and others,I've already provide,and I also searched online for all those unsolved symbol related libs and heards,no clue at all at this moment. Regards, phcute
Feb 22
parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
Wich version of visual studio you have? From what i could find 
online, it could be due to having an older version, try to update 
it if it's too old
Feb 23
parent ptcute <peterhu.peterhu outlook.com> writes:
On Friday, 23 February 2024 at 11:32:15 UTC, ryuukk_ wrote:
 Wich version of visual studio you have? From what i could find 
 online, it could be due to having an older version, try to 
 update it if it's too old
Sorry,forgot to mention this,it is: Windows 10 64bit + dmd 2.106 + VS Community 2019 .
Feb 23
prev sibling parent reply DUser <duser dlang.org> writes:
On Thursday, 22 February 2024 at 01:23:36 UTC, ptcute wrote:
 ...
 So what's the real issue behind?

 Anyone help on this would be appreciated.
They are MSVC compiler intrinsics. (https://issues.dlang.org/show_bug.cgi?id=23894) Surprisingly I got it working by just replacing some includes with definitions in "curl/curl.h". Change: ```c #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) #if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) /* The check above prevents the winsock2 inclusion if winsock.h already was included, since they can't co-exist without problems */ #include <winsock2.h> #include <ws2tcpip.h> #endif #endif ``` to: ```c #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) #if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) typedef unsigned short u_short; typedef unsigned int u_int; typedef struct sockaddr { #if (_WIN32_WINNT < 0x0600) u_short sa_family; #else ADDRESS_FAMILY sa_family; // Address family. #endif //(_WIN32_WINNT < 0x0600) char sa_data[14]; // Up to 14 bytes of direct address. } SOCKADDR; #if(_WIN32_WINNT >= 0x0501) typedef unsigned __int64 u_int64; #endif //(_WIN32_WINNT >= 0x0501) #if defined(_WIN64) typedef unsigned __int64 SOCKET; #else typedef unsigned int SOCKET; #endif #ifndef FD_SETSIZE #define FD_SETSIZE 64 #endif /* FD_SETSIZE */ typedef struct fd_set { u_int fd_count; /* how many are SET? */ SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */ } fd_set; #endif #endif ``` At least this example program (https://curl.se/libcurl/c/getinfo.html) works fine.
Feb 25
parent reply ptcute <peterhu.peterhu outlook.com> writes:
On Sunday, 25 February 2024 at 10:23:26 UTC, DUser wrote:
 On Thursday, 22 February 2024 at 01:23:36 UTC, ptcute wrote:
 ...
 So what's the real issue behind?

 Anyone help on this would be appreciated.
They are MSVC compiler intrinsics. (https://issues.dlang.org/show_bug.cgi?id=23894) Surprisingly I got it working by just replacing some includes with definitions in "curl/curl.h". Change:
 ```
 to:
 ```c
 ```
 At least this example program 
 (https://curl.se/libcurl/c/getinfo.html) works fine.
Thank you for the help. I tried to modify the curl.h header exactly followinging the above information and with the above mentioned simple curl demo,unfortunately the error message are the same.
Feb 25
parent reply DUser <duser dlang.org> writes:
On Sunday, 25 February 2024 at 13:36:43 UTC, ptcute wrote:
 Thank you for the help.

 I tried to modify the curl.h header exactly followinging the 
 above information and with the above mentioned simple curl 
 demo,unfortunately the error message are the same.
Did you remove the "#include <windows.h>" directive from your wrapper module?
Feb 25
parent ptcute <peterhu.peterhu outlook.com> writes:
On Sunday, 25 February 2024 at 21:48:01 UTC, DUser wrote:

 Did you remove the "#include <windows.h>" directive from your 
 wrapper module?
No,and yes,now :) It compiles and runs as expected,another send mail example also works great. To summary,to write a reminder to myself,and a very simple reference to anybody who may encounter this issue and try to fix it--- Environment:Windows 10 64bit,DMD 2.106,VS Community 2019. 1.Modify curl.h as described above; 2.D wrapper file curl_d.c to curl.h: #include <stdio.h> //in my system include string.h is required, //otherwise dmd complains strlen and memcpy is not defined #include <string.h> //in my system #include <curl/curl.h> dosn't work,although //curl ,curl/include,curl/lib is already in system enviroment path //provide curl.h path relative to this wrapper #include "include/curl/curl.h" 3.main.c source file: #include <stdio.h> #include "curl_d.c" int main(void){ return 0;} 4.compile with :dmd -m64 main.c curl_d.c curl.lib That is it. 5.main.d source file: import core.stdc.stdio; import curl_d; //otherwise 2 printf candidates conflict in my system alias printf=core.stdc.stdio.printf;. int main(){ return 0;} 6.compile with dmd:dmd -m64 main.d curl_d.c curl.lib
Feb 25