Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?LNK2019錯誤代碼
當我嘗試編譯我的代碼錯誤LNK2019不斷彈出。所有的論點都是正確的,所以我沒有看到任何問題。有誰知道如何解決這一問題?
Error: LNK2019: unresolved external symbol "char __cdecl countBits(char *)" ([email protected]@[email protected]) referenced in function _main
的main.cpp
#include <stdio.h>
#include <Windows.h>
#include "bitman.h"
int main()
{
int i;
char* string = (char*)malloc(9);
string = "12345678";
printf("%i\n", countBits(string));
for (i = 0; i < 9; i++)
{
printf("%x-", string[i]);
}
getchar();
}
bitman.cpp
unsigned int countBits(char* invoer)
{
char buf;
unsigned int i, i2, teller = 0;
for (i = 0; i < strlen(invoer); i++)
{
for (i2 = 0; i < 7; i++)
{
buf = invoer[i];
buf &= (1 << i2);
if (buf == 1)
{
teller++;
}
}
}
return teller;
}
bitman.h
#ifndef BIT_MANIPULATION
#define BIT_MANIPULATION
char testBit(unsigned char byte, char place);
unsigned char setBit(unsigned char byte, char place);
unsigned char clearBit(unsigned char byte, char place);
unsigned char toggleBit(unsigned char byte, char place);
unsigned char rol(unsigned char byte);
unsigned char ror(unsigned char byte);
char countBits(char invoer);
char countBits(char* invoer);
#endif
bitmain.cpp是否包含在與main.cpp相同的csproj文件中? – simonc
是的,它在同一個項目中。 – para
嘗試將'extern'放在函數的執行上? –