gpt4 book ai didi

c++ - C 代码编译为 C++,但不是 C

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:57:47 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Convert some code from C++ to C

我有一些看起来是纯 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 .

如有任何帮助,我们将不胜感激。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com