Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 链接器在对象文件中找不到现有引用_C++_Linker_G++ - Fatal编程技术网

C++ 链接器在对象文件中找不到现有引用

C++ 链接器在对象文件中找不到现有引用,c++,linker,g++,C++,Linker,G++,我在编译一个项目时遇到了麻烦,基本上是链接对象。链接器抱怨: $ g++ -o bin/program obj/linux64/Debug/src/main.o [... more object files ...] ../../../addons/obj/linux64/Debug/ofxLua/libs/lua/lua/lapi.o [...many other object files and libraries...] ../../../addons/obj/linux64/Debug

我在编译一个项目时遇到了麻烦,基本上是链接对象。链接器抱怨:

$ g++ -o bin/program obj/linux64/Debug/src/main.o  [... more object files ...] ../../../addons/obj/linux64/Debug/ofxLua/libs/lua/lua/lapi.o [...many other object files and libraries...]
../../../addons/obj/linux64/Debug/ofxLua/libs/luabind/src/scope.o: In function `~lua_pop_stack':
../../../addons/ofxLua/libs/luabind/src/scope.cpp:122: undefined reference to `lua_settop(lua_State*, int)'
[...many more undefined reference errors...]
但如果我检查对象文件,我会发现符号:

$ nm ../../../addons/obj/linux64/Debug/ofxLua/libs/lua/lua/lapi.o | grep lua_settop
000000000000045c T lua_settop
我检查了g++参数


这种行为的原因是什么?我能想到的唯一解释是,不同源文件中使用的头文件被以前的include或defines以某种方式更改。是否有任何方法可以检查结果的完整符号,所以我可以肯定是这样的吗?< /P> < P>如果你在C中包含了代码的头,你需要在 Extn(c){}……/Cube >中包含<代码>包含< < /Cord>语句>,以便C++编译器知道使用C链接来代替那些符号,而不是C++链接。(它使用名称混乱来允许方法重载)

例如:

extern "C" {
#include <file.h>
}

那么,Lua是C库吗?我本来以为这个方法是被破坏的,如果是C++,我认为是。是一个C库,所以有一个<代码>外c{包含} /c>或在Lua头文件中,这样C++编译器知道使用C链接吗?@ Tr.OrgFoFe,谢谢!请回答我的问题,我可以接受它吗?
//
// file.h
//
#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}    // extern "C"
#endif