问题描述
||
我昨天问了同样的问题,答案不适用。
https://stackoverflow.com/questions/6194578/breaking-up-class-functions-into-multiple-cpp-files
如果我进入类标题,请右键单击该函数,然后单击\“转到定义\”,这将使我直接进入我的其他.CPP文件中的函数。它看到了,可以链接到它,但是仍然出现错误,表明我看不到它。
有人有什么建议吗?我会尝试的。
这又是错误。
zdll.lib(d000050.o):警告LNK4078:找到多个具有不同属性的
\'.text\'
节(E0300020)
WLD.obj:错误LNK2019:函数\"public: bool __thiscall WLD::init(unsigned char *)\" (?init@WLD@@QAE_NPAE@Z)
中引用的未解析的外部符号\"public: void __thiscall WLD::fragment_03(unsigned char *,int)\" (?fragment_03@WLD@@QAEXPAEH@Z)
编辑:另外,我正在使用MSVC ++。我应该尝试创建新的解决方案并导入文件吗?可能会有所帮助,因为我感觉自己选择不了...
编辑:这是代码:
#include \"WLD.h\"
inline void WLD::fragment_03(uchar* location,int frag_num)
{
// Read the struct into memory and create a temporary pointer
struct_frag03 temp03;
memcpy(&temp03,location,sizeof(struct_frag03));
uchar* temp_p = location;
// Advance the pointer to the encoded bytes (filename)
temp_p += sizeof(long) + sizeof(short);
// Grab the encoded filename and decode it
uchar* f_filename = new uchar [sizeof(temp03.nameLen + 1)];
memcpy(f_filename,temp_p,temp03.nameLen + 1);
decode(f_filename,temp03.nameLen);
// Add the details about this bitmap to the array
bmp_array[current_bmp].filename = f_filename;
bmp_array[current_bmp].nameLength = temp03.nameLen;
bmp_array[current_bmp].reference03 = frag_num;
// 0x03 Debug
//errorLog.OutputSuccess(\"0x03 Filename: %s\",bmp_array[current_bmp].filename);
//errorLog.OutputSuccess(\"0x03 Name length: %i\",bmp_array[current_bmp].nameLength);
//errorLog.OutputSuccess(\"0x03 Reference: %i\",bmp_array[current_bmp].reference03);
// Add the bitmap to the count
current_bmp++;
}
这是在WLD类中调用代码的位置:
case 0x03:
fragment_03(wld + file_pos + sizeof(struct_wld_basic_frag),i);
break;
这是头文件的声明:在(WLD.h)中:
public:
inline void fragment_03(uchar* location,int frag_num);
解决方法
“ 6”表示该功能有效地具有内部链接(也就是说,该功能必须存在于使用该功能的翻译单元内部)。将函数的定义移到标题中,或删除“ 6”。
(对于现代编译器而言,“ 6”实际上意味着“使用内部链接”-编译器会内联起来对自己有意义),并且通常比人类做出更好的决策)
编辑:从技术上讲,该标准在此使用的语言表示内联函数具有外部链接;但是,它在标准的第3.2条第3款中也表示为“ 9”,在第5段中也表示为“ 10”。因此,从技术上讲,您声明的内联名称可从给定的翻译单元外部访问,但这样做会导致未定义的行为。 C ++。
, 这与包含无关。您所拥有的存在链接器错误。包括所有与编译有关的内容,这需要声明引用的标识符。
您遇到的错误意味着链接器无法在传递给函数的任何一个目标文件中找到一个函数的定义,该目标文件被一个或多个调用。 (请参阅此答案以了解什么是声明,什么是定义以及所需的内容。)
您需要将通过编译所有
.cpp
文件创建的目标文件传递给链接器。如果您使用某种类型的IDE,则应在将所有.cpp
文件添加到项目中时为您执行此操作。如果使用的是makefile,请列出所有.cpp
个文件作为目标的依赖项。如果通过手动调用编译器(然后调用链接器)进行编译,请在同一调用中将所有.cpp
文件传递给它。