简体   繁体   English

努力编译简单的C程序(gcc)

[英]Struggling compiling a simple c program (gcc)

I have a very old C program and want to compile to Windows. 我有一个非常老的C程序,想编译到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: ekiGetLibVersion在.h文件中:

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

and I also have a .dll name of it. 而且我也有一个.dll名称。

Ive never compiled anything with C though 我从来没有用C编译过任何东西

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. 在Windows上,您无法直接与.dll链接,您必须链接名为.lib的导入库。 For more information, refer: 有关更多信息,请参阅:

On dynamic linking: 在动态链接上:

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

On implicit linking: 在隐式链接上:

https://msdn.microsoft.com/en-us/library/d14wsce5.aspx https://msdn.microsoft.com/zh-CN/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 ? 您是否在C程序中包含头文件(定义此变量)?

#include "header_file.h"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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