简体   繁体   中英

Struggling compiling a simple c program (gcc)

I have a very old C program and want to compile to Windows. So I try doing this:

gcc -DNO_GLIBC=1 sakide.c -o sakide.exe

and this returns:

\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa4): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x6b6): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x8ff): undefined reference to `ekiEncodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x954): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x993): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa62): undefined reference to `ekiGetKeyInfo'
collect2.exe: error: ld returned 1 exit status

This ekiGetLibVersion is in a .h file:

INT EKIAPI ekiGetLibVersion(char *outBuffer, LPINT outBufferSize);

and I also have a .dll name of it.

Ive never compiled anything with C though

You are getting linker errors.

You need to link the library (or object file) where those functions are defined.

On windows you cannot link against directly with the .dll, you have to link the import library, name .lib. For more information, refer:

On dynamic linking:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592(v=vs.85).aspx

On implicit linking:

https://msdn.microsoft.com/en-us/library/d14wsce5.aspx

Undefined reference usually means the compiler has not seen a proper declaration for this variable. Did you include the header file (which defines this variable) in your C program ?

#include "header_file.h"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM