简体   繁体   English

使用非标准标头编译C

[英]Compiling C with non standard header

I have my main C file: 我有我的主要C文件:

#if defined(WIN32)
#include <windows.h>
#include <stddef.h>
#endif
#if defined(LINUX)
#include <curses.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(WIN32)
#include <conio.h>
#endif
#include <ctype.h>
#include <a429usbnt.h>

#if defined(WIN32)
#include "genlib.h"
#endif

void main()
{
    _open_xpc(1);
}

When I try to compile using this command 当我尝试使用此命令进行编译时

gcc -I. -L. test.c -o test 

I get the following error: undefined reference to '_open_xpc' . 我收到以下错误: 对'_open_xpc'的未定义引用

However if I change the call to the _open_xpc function and instead just 但是,如果我将调用更改为_open_xpc函数,而只是

printf("%d", XPC_ERROR_ACTIONCODE);

the program compiles fine and the correct value assigned to the definition of XPC_ERROR_ACTIONCODE is printed out, so the compiler is linking a429usbnt.h but will only recognize defined variables and not the functions. 程序可以正常编译,并且分配给XPC_ERROR_ACTIONCODE定义的正确值被输出,因此编译器链接a429usbnt.h,但仅识别定义的变量,而不识别函数。

如果您尝试使用gcc链接.lib文件,则似乎需要使用-L定义目录,并使用-l定义实际文件

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

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