我的项目由几个静态库组成,这些库在最后一步中链接在一起.现在我遇到了问题,库的链接顺序很重要(否则我得到一个未定义的符号链接器错误).有时我遇到问题,我必须重新排序链接库(-lcommon -lsetup -lcontrol等).目前这是一个愚蠢的试验和错误:重新排序,编译,检查错误,重新排序,编译等等.
所以我写了一个小程序来向我展示库间依赖关系,并生成链接库的顺序.它从nm读取定义的('T','B'等)和未定义的符号('U')并从中删除弱符号('w','W','v'和'V') '未定义的符号列表'.现在它为每个未定义的符号确定解析它的库.
但我的程序向我展示了循环依赖...我的错误是什么?
如果它们真的存在,我根本无法联系......那么在分析nm输出时我错过了什么?或者正在分析nm输出而不是解决这些依赖关系?
libcommon.a:
U _ZN15HardwareUnit23GetHardwareSerialNumberEv
libhardware.a:
00000484 T _ZN15HardwareUnit23GetHardwareSerialNumberEv
libsecurityaccess.a:
U _ZN15HardwareUnit23GetHardwareSerialNumberEv
---
libhardware.a:
U _ZN21ApplicationProfile26GetApplicationSettingsPathERK7QString
libsecurityaccess.a:
00004020 T _ZN21ApplicationProfile26GetApplicationSettingsPathERK7QString
U _ZN21ApplicationProfile26GetApplicationSettingsPathERK7QString
Run Code Online (Sandbox Code Playgroud) 我正在使用GCC 4.5.2和Boost 1.46.1(编译--build-type=complete)构建一个共享库,这是来自Makefile的命令,它执行链接部分:
$(CXX) -static -lboost_filesystem -fpic -shared $^ -o $@
Run Code Online (Sandbox Code Playgroud)
一切都编译得很好但是当它被应用程序加载时我得到以下错误:
plugins/crashdetect.so: undefined symbol: _ZN5boost11filesystem34path21wchar_t_codecvt_facetEv
Run Code Online (Sandbox Code Playgroud)
ldd输出:
linux-gate.so.1 => (0x002f8000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00bf5000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x0032d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00506000)
/lib/ld-linux.so.2 (0x006f6000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0x00110000)
Run Code Online (Sandbox Code Playgroud)
我相信这意味着它静态地联系了Boost.
这nm crashdetect.so -u | grep boost就是说:
U _ZN5boost11filesystem34path21wchar_t_codecvt_facetEv
U _ZN5boost11filesystem36detail13dir_itr_closeERPvS3_
U _ZN5boost11filesystem36detail28directory_iterator_constructERNS0_18directory_iteratorERKNS0_4pathEPNS_6system10error_codeE
U _ZN5boost11filesystem36detail28directory_iterator_incrementERNS0_18directory_iteratorEPNS_6system10error_codeE
U _ZN5boost11filesystem36detail6statusERKNS0_4pathEPNS_6system10error_codeE
U _ZN5boost6system15system_categoryEv
U _ZN5boost6system16generic_categoryEv
U _ZNK5boost11filesystem315directory_entry12m_get_statusEPNS_6system10error_codeE
Run Code Online (Sandbox Code Playgroud)
所以我认为,因为这个符号在这个列表中排在第一位,所以很可能没有什么特别之处.
我错过了什么吗?
编辑: 那么这不可能或者是什么?
请仔细阅读以确保您了解我想要做的事情.
我做了什么(也作为可能想要做同样事情的人的未来参考):
我已将以下路径添加到页眉搜索路径和库搜索路径:
(如果您已在"应用程序"文件夹以外的位置安装了Arduino.app,则需要相应地调整路径.)
在main.cpp中,我已经包含了<WProgram.h>,但这还不够.我正在未定义的标识符错误(SPCR,SPE,MSTR,SPR1,SPR0)由于不能够传递到-mmcu=somechipname作为一个标志给编译器,这引起了不设备加以界定和avr/io.h以不能包括限定的文件那些符号.我通过手动包括<avr/iom328p.h>哪个是我的芯片的适当头文件.
那是我有多远.
现在我收到这些错误:
Undefined symbols for architecture i386:
"_init", referenced from:
_main in main.o
"_setup", referenced from:
_main in main.o
"_loop", referenced from:
_main in main.o
"_pinMode", referenced from:
SBSetup() in main.o
"_digitalWrite", referenced from:
SBSetup() in main.o
Run Code Online (Sandbox Code Playgroud)
整个main.cpp包括邪恶的违规代码是这样的:
#include <WProgram.h>
#include <avr/iom328p.h> // Getting around warning "device type not defined"
#define NumLEDs 25
#define clockpin 13 // CI
#define …Run Code Online (Sandbox Code Playgroud) 我有以下情况:
我创建了动态库lib.so。该库使用另一个静态库lib.a。它们都使用 Boost 库(我将它们链接到 CMake 文件中)。(我在Java项目中使用这个动态库)
这是lib.so中file.cpp的代码,它从lib.a调用getFilesFromDirectory()
#include "DrawingDetector.h"
#include "../../DrawingDetection.h"
#include <vector>
#include <boost/filesystem/operations.hpp>
using namespace std;
JNIEXPORT void JNICALL Java_DrawingDetector_detectImage( JNIEnv * env, jobject, jstring jMsg)
{
const char* msg = env->GetStringUTFChars(jMsg,0);
vector<File> filesPic = getFilesFromDirectory(msg,0);
env->ReleaseStringUTFChars(jMsg, msg);
}
Run Code Online (Sandbox Code Playgroud)
这是 lib.a 中 getFilesFromDirectory() 的代码:
#include <string.h>
#include <iostream>
#include <boost/filesystem/operations.hpp>
#include "DrawingDetection.h"
using namespace std;
using namespace boost;
using namespace boost::filesystem;
vector<File> getFilesFromDirectory(string dir, int status)
{
vector<File> files;
path directoty = path(dir);
directory_iterator end;
if (!exists(directoty))
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用CentOS 6.3的devtoolset-1.0来临时升级GCC版本。尽管我现在可以编译我的C ++应用程序,但最终的二进制文件缺少一些符号:
$ ldd -d -r myapp
$ [..]
$ libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003216e00000)
$ [..]
$ undefined symbol: _ZNSt8__detail15_List_node_base11_M_transferEPS0_S1_ (./myapp)
$ undefined symbol: _ZNSt8__detail15_List_node_base7_M_hookEPS0_ (./myapp)
$ undefined symbol: _ZNSt8__detail15_List_node_base9_M_unhookEv (./myapp)
Run Code Online (Sandbox Code Playgroud)
我发现,这些是一些新功能,在旧的libstdc ++中找不到,但是在较新的libstdc ++中找不到。在我的系统上,同时安装了libstdc ++(默认版本4.4.7)和devtoolset-1.0-libstdc ++-devel(4.7通过devtoolset)。有趣的是,来自devtoolset的libstdc ++再次链接到旧的:
$ cat /opt/centos/devtoolset-1.0/root/usr/lib/gcc/x86_64-redhat-linux/4.7.0/libstdc++.so
$ /* GNU ld script
$ Use the shared library, but some functions are only in
$ the static library, so try that secondarily. */
$ OUTPUT_FORMAT(elf64-x86-64)
$ INPUT ( /usr/lib64/libstdc++.so.6 -lstdc++_nonshared )
Run Code Online (Sandbox Code Playgroud)
我真正想要的是替换libstdc ++绑定,但是我不知道该如何实现。我已经尝试设置LD_LIBRARY_PATH并指向devtoolset目录,但是libstdc ++仍然设置为旧位置。另外,符号链接也没有成功,因为它是ld脚本而不是实际的共享库。
我试图使用链接器符号自动设置我的可执行文件中的版本号,只要符号未设置为零,它似乎工作...
在我的C代码中:
extern char __VERSION_MAJ;
extern char __VERSION_MIN;
...
printf("Version %u.%u\n", (unsigned) &__VERSION_MAJ, (unsigned) &__VERSION_MIN);
Run Code Online (Sandbox Code Playgroud)
在我的makefile中:
LDFLAGS += -Xlinker --defsym=__VERSION_MAJ=1
LDFLAGS += -Xlinker --defsym=__VERSION_MIN=0
Run Code Online (Sandbox Code Playgroud)
当我尝试运行可执行测试时,得到以下输出结果:
./test: symbol lookup error: ./test: undefined symbol: __VERSION_MIN
Run Code Online (Sandbox Code Playgroud)
如果我更改符号定义如下:
LDFLAGS += -Xlinker --defsym=__VERSION_MAJ=1
LDFLAGS += -Xlinker --defsym=__VERSION_MIN=1
Run Code Online (Sandbox Code Playgroud)
然后它工作得很好:
Version 1.1
Run Code Online (Sandbox Code Playgroud)
我在http://web.eecs.umich.edu/~prabal/teaching/eecs373-f10/readings/Linker.pdf上阅读了有关链接器符号的内容并浏览了google,但没有发现任何说0是不允许值的内容用于自定义链接器符号
另外,如果我查看链接器映射输出,它确实有__VERSION_MIN:
0x0000000000000001 __VERSION_MAJ = 0x1
0x0000000000000000 __VERSION_MIN = 0x0
Run Code Online (Sandbox Code Playgroud)
所以,我很难过!
我只是使用gcc -D__VERSION_MIN = 0,但是当版本发生变化时,使用先决条件重建应用程序会导致棘手和makefile丑陋(它将存储在文本文件中,而不是如上所述在makefile中硬编码. )
我正在为目标i686-linux-gnu编译和链接gcc版本4.6.3(Ubuntu/Linaro 4.6.3-1ubuntu5),如果其中任何一个有所不同.
执行摘要:
用pip安装python-igraph后,我仍然无法导入它。我在互联网上遇到过这样的错误,但我发现的大多数解决方案都是关于重新安装模块,我已经这样做了。任何有关如何解决此问题的建议将不胜感激。谢谢
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/site-packages/igraph/__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: /usr/lib/python3.5/site-packages/igraph/_igraph.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZTVN10__cxxabiv121__vmi_class_type_infoE
Run Code Online (Sandbox Code Playgroud) 我对Unix世界还很陌生,我正在尝试安装一个名为Meep的软件来进行物理模拟。为此,我需要在Mac OS X 10.10.5上安装大量的库。我成功完成了许多任务,但是在名为pkg-config的脚本(对glib起作用)命令“ configure”时出现以下错误。
CCLD pkg-config
Undefined symbols for architecture x86_64:
"_CFRelease", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetCString", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetCStringPtr", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetLength", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFURLCopyFileSystemPath", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFURLCreateFromFSRef", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_FSFindFolder", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_kCFAllocatorSystemDefault", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
ld: symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)
环顾四周,我已经知道这可能是这些符号的链接器问题,但本质上我不知道要解决该问题。有谁能够帮助我?
我已经看到过类似问题的部分答案,但从未真正解决过这个问题。我将其简化为一个最小的应用程序以演示该问题。
我正在使用最新版本的Android Studio(V2.2.1),并且安装了以下SDK:
Android支持存储库v32
每个更新了build.gradle(app):https : //developer.android.com/training/testing/start/index.html#config-instrumented-tests
在defaultConfig下添加:
在依赖项下添加
项目是否已同步以同步Gradle
在“测试”包下,添加新的测试文件-ExampleIntegrationTest.java(在ExampleUnitTest.java旁边)
在新文件中,根据以下网址创建集成测试:https : //developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public interface ExampleIntegrationTest {
}
Run Code Online (Sandbox Code Playgroud)
这就是问题所在-无法解析符号AndroidJUnit4在线上:import android.support.test.runner.AndroidJUnit4;
如果输入import语句,我可以使用弹出建议:
-导入android。-显示“支持作为选项”
-导入android.support。-显示“测试”作为选项
-导入android.support.test。-现在仅显示“规则”作为选项
创建应用后,请确保使用的是“ debug”变体
这是很干的。据我所知,这应该可行,但是由于某种原因,支持库无法正确导入。
android integration-testing compiler-errors undefined-symbol android-studio
我正在尝试从名为 的小型 cc (tcc-0.9.26-win64-bin.zip)运行该示例libtcc_test.c。
我已将libtcc.hfrom libtccintoinclude复制libtcc.def到lib.
然后我运行tcc ./examples/libtcc_test.c并收到链接错误:/
tcc: error: undefined symbol 'tcc_new'
tcc: error: undefined symbol 'tcc_set_lib_path'
tcc: error: undefined symbol 'tcc_set_output_type'
tcc: error: undefined symbol 'tcc_compile_string'
tcc: error: undefined symbol 'tcc_add_symbol'
tcc: error: undefined symbol 'tcc_relocate'
tcc: error: undefined symbol 'tcc_get_symbol'
tcc: error: undefined symbol 'tcc_delete'
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
更多信息:
P:\cpp\tcc>tcc ./examples/libtcc_test.c -vv
tcc version 0.9.26 (i386 Win32)
-> ./examples/libtcc_test.c
-> p:/cpp/tcc/include/stdlib.h
-> p:/cpp/tcc/include/_mingw.h
-> …Run Code Online (Sandbox Code Playgroud)