Possible Duplicate:
Convert some code from C++ to CC代碼編譯爲C++,但不是爲C
我有一個看起來是直的。當我告訴編譯器一些代碼(我使用Visual Studio 2008 Express的)編譯它作爲C++,它編譯和鏈接罰款。當我嘗試編譯爲C,雖然,它拋出這個錯誤:
1>InpoutTest.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main
1>InpoutTest.obj : error LNK2019: unresolved external symbol [email protected] 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++的名稱,除非我很困惑,但那些肯定不是未修飾的函數名稱。 – Steve314 2010-06-29 17:19:22
這只是你以前的問題的一個小改寫:http://stackoverflow.com/questions/3142420/convert-some-code-from-c-to-c。儘量不要加倍張貼。 – 2010-06-29 17:21:01
@Evan:我再次問,因爲我沒有得到新的問題。抱歉。 – 2010-06-29 17:23:51