【发布时间】:2010-06-29 17:11:17
【问题描述】:
我有一些看起来是纯 C 的代码。当我告诉编译器(我使用 Visual Studio 2008 Express)将其编译为 c++ 时,它可以正常编译和链接。但是,当我尝试将其编译为 C 时,它会引发此错误:
1>InpoutTest.obj : error LNK2019: unresolved external symbol _Out32@8 referenced in function _main
1>InpoutTest.obj : error LNK2019: unresolved external symbol _Inp32@4 referenced in function _main
代码使用 Inpout.dll 读取和写入并行端口。我有 Inpout.lib 和 Inpout.dll。代码如下:
// InpoutTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
/* ----Prototypes of Inp and Outp--- */
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
/*--------------------------------*/
int main(int argc, char* argv[])
{
int data;
if(argc<3)
{
//too few command line arguments, show usage
printf("Error : too few arguments\n\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
}
else if(!strcmp(argv[1],"read"))
{
data = Inp32(atoi(argv[2]));
printf("Data read from address %s is %d \n\n\n\n",argv[2],data);
}
else if(!strcmp(argv[1],"write"))
{
if(argc<4)
{
printf("Error in arguments supplied");
printf("\n***** Usage *****\n\nInpoutTest read <ADDRESS> \nor \nInpoutTest write <ADDRESS> <DATA>\n\n\n\n\n");
}
else
{
Out32(atoi(argv[2]),atoi(argv[3]));
printf("data written to %s\n\n\n",argv[2]);
}
}
return 0;
}
我之前问错了这个问题,here。
任何帮助将不胜感激。
【问题讨论】:
-
这些天 C 是否使用重命名?我正在查看链接器错误中的
@4和@8。看起来不像 C++ 名称修饰,除非我很困惑,但这些肯定不是未修饰的函数名称。 -
这只是对您上一个问题的小改写:stackoverflow.com/questions/3142420/…。尽量不要重复发帖。
-
@Evan:我重新提问是因为我没有对另一个问题提出新的意见。对不起。
-
@Steve Visual Studio 将 _stdcall C 函数转换为 _name@number-of-bytes-passed-as-arguments;
Inp32有 4 个字节的参数,而Out32有 8 个。(reference) -
@Michael - 有道理,谢谢
标签: c++ c visual-studio