www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How include header file?

reply Injeckt <vinsentlou9 gmail.com> writes:
I need to include this Ws2tcpip.h header file to my project. How 
can I do this? It's all because I need inet_ntop function from 
this header file.
Sep 07 2022
parent reply "H. S. Teoh" <hsteoh qfbox.info> writes:
On Wed, Sep 07, 2022 at 06:11:14PM +0000, Injeckt via Digitalmars-d-learn wrote:
 I need to include this Ws2tcpip.h header file to my project. How can I
 do this? It's all because I need inet_ntop function from this header
 file.
If that's the only function you need, you can just copy the declaration of inet_ntop into your .d file and mark it as extern(C). E.g., on my OS it's declared as: const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); Convert it to D: extern(C) const(char)* inet_ntop(int af, const(void)* src, char* dst, socklen_t size); You probably also need: alias socklen_t = ...; The definition can be found in your system header files. Probably you can just get away with size_t. T -- The volume of a pizza of thickness a and radius z can be described by the following formula: pi zz a. -- Wouter Verhelst
Sep 07 2022
parent reply Injeckt <vinsentlou9 gmail.com> writes:
On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh wrote:
 On Wed, Sep 07, 2022 at 06:11:14PM +0000, Injeckt via 
 Digitalmars-d-learn wrote:
 I need to include this Ws2tcpip.h header file to my project. 
 How can I do this? It's all because I need inet_ntop function 
 from this header file.
If that's the only function you need, you can just copy the declaration of inet_ntop into your .d file and mark it as extern(C). E.g., on my OS it's declared as: const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); Convert it to D: extern(C) const(char)* inet_ntop(int af, const(void)* src, char* dst, socklen_t size); You probably also need: alias socklen_t = ...; The definition can be found in your system header files. Probably you can just get away with size_t. T
It doesn't work. "Reference to an unresolved external symbol _inet_ntop". I guess I can add my utils.c to my .d project when I compile project and I need write in this file function wrapper of inet_ntop.
Sep 07 2022
next sibling parent Injeckt <vinsentlou9 gmail.com> writes:
On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
 _inet_ntop". I guess I can add my utils.c to my .d project when 
 I compile project and I need write in this file function 
 wrapper of inet_ntop.
No, it doesn't work. Jesus I need to figure out how to add WS2tcpip.h
Sep 07 2022
prev sibling next sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 9/7/22 4:23 PM, Injeckt wrote:
 On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh wrote:
 On Wed, Sep 07, 2022 at 06:11:14PM +0000, Injeckt via 
 Digitalmars-d-learn wrote:
 I need to include this Ws2tcpip.h header file to my project. How can 
 I do this? It's all because I need inet_ntop function from this 
 header file.
If that's the only function you need, you can just copy the declaration of inet_ntop into your .d file and mark it as extern(C). E.g., on my OS it's declared as:     const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); Convert it to D:     extern(C) const(char)* inet_ntop(int af, const(void)* src, char* dst, socklen_t size); You probably also need:     alias socklen_t = ...; The definition can be found in your system header files. Probably you can just get away with size_t. T
It doesn't work. "Reference to an unresolved external symbol _inet_ntop". I guess I can add my utils.c to my .d project when I compile project and I need write in this file function wrapper of inet_ntop.
On windows, it might have different versions based on character width. Don't have time right now to look it up on my windows system. -Steve
Sep 07 2022
prev sibling next sibling parent reply Loara <loara noreply.com> writes:
On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
 On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh 
 wrote:
 On Wed, Sep 07, 2022 at 06:11:14PM +0000, Injeckt via 
 Digitalmars-d-learn wrote:
 I need to include this Ws2tcpip.h header file to my project. 
 How can I do this? It's all because I need inet_ntop function 
 from this header file.
If that's the only function you need, you can just copy the declaration of inet_ntop into your .d file and mark it as extern(C). E.g., on my OS it's declared as: const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); Convert it to D: extern(C) const(char)* inet_ntop(int af, const(void)* src, char* dst, socklen_t size); You probably also need: alias socklen_t = ...; The definition can be found in your system header files. Probably you can just get away with size_t. T
It doesn't work. "Reference to an unresolved external symbol _inet_ntop". I guess I can add my utils.c to my .d project when I compile project and I need write in this file function wrapper of inet_ntop.
You need to link the DLL to your project. Which DLL contains the definiton of `inet_ntop`?
Sep 07 2022
parent Injeckt <vinsentlou9 gmail.com> writes:
On Wednesday, 7 September 2022 at 22:57:53 UTC, Loara wrote:
 On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
 On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh 
 wrote:
 On Wed, Sep 07, 2022 at 06:11:14PM +0000, Injeckt via 
 Digitalmars-d-learn wrote:
You need to link the DLL to your project. Which DLL contains the definiton of `inet_ntop`?
ws2_32.dll
Sep 07 2022
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:

 Convert it to D:

 	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
 char* dst, socklen_t size);
Win32 API functions need to be `extern(Windows)`.
 You probably also need:

 	alias socklen_t = ...;
https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d#L17 `alias socklen_t = int`
 It doesn't work. "Reference to an unresolved external symbol 
 _inet_ntop".
That's a linker error. You need to link with `ws2_32.lib`.
Sep 07 2022
parent Injeckt <vinsentlou9 gmail.com> writes:
On Wednesday, 7 September 2022 at 23:01:34 UTC, Mike Parker wrote:
 On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:

 Convert it to D:

 	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
 char* dst, socklen_t size);
Win32 API functions need to be `extern(Windows)`.
 You probably also need:

 	alias socklen_t = ...;
https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d#L17 `alias socklen_t = int`
 It doesn't work. "Reference to an unresolved external symbol 
 _inet_ntop".
That's a linker error. You need to link with `ws2_32.lib`.
Thank you so much. Now It works!
Sep 07 2022