简体   繁体   English

未定义对..错误的引用(Linux)-在OSX中可以正常编译

[英]Undefined reference to .. error (Linux) - Compiles fine in OSX

Have wasted almost full 4 days trying to compile this package. 试图编译此软件包浪费了将近4天。 It compiles fine in OSX 10.6, but gives Undefined reference errors when I try to compile it on a linux (Kubuntu 10.04, 3.8.0.27 kernel) machine. 它可以在OSX 10.6中正常编译,但是当我尝试在Linux(Kubuntu 10.04、3.8.0.27内核)计算机上进行编译时,会给出未定义的引用错误。

The error seem to be that the makefiles are ordered wrong, but AFAIK, I am the only one having trouble compiling it. 错误似乎是makefile的顺序错误,但是AFAIK是唯一一个编译困难的文件。 So I'm trying to find what's making the difference. 因此,我正在尝试找出产生差异的原因。 The software package is quite big and editing the Makefiles and moving 30-50 libraries here and there doesn't seem like a good idea. 该软件包很大,可以编辑Makefile并在此处移动30-50个库,这似乎不是一个好主意。

Here's the differences I think I found so far 这是我到目前为止发现的差异

  • Compiler - gcc-4.7 (Linux) and llvm-gcc-4.2 (OSX) 编译器-gcc-4.7 (Linux)和llvm-gcc-4.2 (OSX)
  • Compiler flags --shared (Linux) and -dynamic -dynamiclib -undefined dynamic_lookup (OSX) 编译器标志--shared (Linux)和-dynamic -dynamiclib-未定义的dynamic_lookup (OSX)

Anyone have any suggestions? 有人有什么建议吗?

  1. I tried using clang++ and llvm-gcc-4.7 as the compiler, but I think it still used the same linker ( ld ?). 我尝试使用clang++llvm-gcc-4.7作为编译器,但我认为它仍使用相同的链接器( ld ?)。 So I could try to specify to use llvm ? 所以我可以尝试指定使用llvm吗? How do I do that? 我怎么做?

  2. is --shared flag somehow different from the dynamic -dynamiclib -undefined dynamic_lookup flags in OSX? --shared国旗从某种程度上不同的dynamic -dynamiclib -undefined dynamic_lookup在OSX的标志吗?

  3. Does the linux kernel or distribution matter? linux内核或发行版重要吗? (I think they compiled it fine on a CentOS machine) (我认为他们在CentOS机器上编译良好)

Please help. 请帮忙。 Thanks a lot. 非常感谢。

Compiled it with gcc 4.4 and worked flawlessly. 使用gcc 4.4进行了编译,并且可以完美地工作。 I guess the order doesn't matter on 4.4 for the given package. 我想对于给定的包,顺序在4.4上无关紧要。

The undefined references type of errors can be caused by a symbol not being compiled in, not being linked or being linked out of order. 错误的未定义引用类型可能是由于未编译符号,未链接或链接顺序混乱而引起的。 The way to debug this is to check the linker line, the symbol that the linker complains about. 调试方法是检查链接器行,链接器抱怨的符号。 The error message will probably tell you what object file has the dependency. 该错误消息可能会告诉您哪个目标文件具有依赖性。

Now, you need to find out whether the symbol is compiled or linked, for that you will need to find if it is in any of the object files or in any of the libraries and which. 现在,您需要查找符号是已编译还是链接的,为此,您将需要查找符号是否在任何目标文件或任何库中以及位于哪个库中。 You can use the nm command line tool to list the symbols that are defined in any given .o or library. 您可以使用nm命令行工具列出在任何给定的.o或库中定义的符号。 If the symbol is not there, then you need to figure out what to add to the linker line and that will solve it. 如果该符号不存在,则需要找出要添加到链接器行的内容,然后才能解决该问题。

If the symbol appears in one library, then identify which of the libraries depends on that symbol (from the linker error message) and the library that contains it. 如果该符号出现在一个库中,则从链接器错误消息中识别出哪个库取决于该符号以及包含该符号的库。 The former must be listed before the latter in the linker command line (assuming static linking). 必须在链接器命令行中将前者列在后者之前(假定静态链接)。

As a simple hack , although I recommend against it, you can instruct the gcc linker to do multiple passes by using the --start-group and --end-group command line options . 作为一个简单的技巧 ,尽管我建议不要这样做,但是您可以使用--start-group--end-group 命令行选项指示gcc链接器进行多次传递。 Although I really recommend that you figure out the order of dependencies, as that will also give you a better insight into your project. 尽管我确实建议您弄清楚依赖关系的顺序,因为这也可以使您更好地了解项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JetBrains CLion 在运行项目时给出“未定义的引用”错误,但命令行编译得很好 - JetBrains CLion gives "undefined reference to" error when running project but command line compiles just fine 编译报错:Undefined reference,主要是对库的依赖导致的? - Compiles error:Undefined reference, which is caused mainly by dependency with libraries? 在linux上预制未定义的引用错误 - Premake undefined reference error on linux Qt跨平台问题:在Windows上编译正常,在Linux上链接程序错误 - Qt cross-platform issue: compiles fine on Windows, linker error on Linux Clang不工作。 未定义的符号错误。 代码在gcc中编译良好 - Clang not working. Undefined symbol error. Code compiles fine in gcc Linux C++ 错误:未定义对“dlopen”的引用 - Linux c++ error: undefined reference to 'dlopen' OpenGL 在 Arch Linux - Linker 错误:未定义的参考 - OpenGL on Arch Linux - Linker Error: Undefined Reference Eclipse显示错误,但gcc编译正常 - Eclipse shows an error but gcc compiles fine CMAKE MAC OSX库链接问题:在Linux上编译但在Mac上编译 - CMAKE MAC OSX library linking Issue: compiles on Linux but on on Mac 编译C ++代码时出错“未定义引用”,但原始makefile代码编译 - Error “undefined reference to” when I compile a C++ code, but the original makefile code compiles
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM