由一次 symbol lookup error 引发的思考
开发一个跨平台的项目的时候,大部分时候都是在VS下进行编码,所以也就使用了VS的解决方案来管理项目。
因为要跨平台,当时网上看scons
这个工具不错,所以在linux下就使用了scons
来作为编译脚本。
linux(gcc)下与windows(vs)下的对于链接这一步稍有不同。当目标文件是一个(共享)库的时候,VS会在链接的时候就去解析所有用到的符号,而gcc则不会,只有在生成最终可执行程序的时候才会去解析。
所以在VS下,一直都没有问题。linux下进行测试的时候也没有问题(因为不是所有的代码都被调用了)。
这几天在一次移植过程中出现了如下的问题
/a.out: symbol lookup error: ./uds_file_storage_module.so: undefined symbol: _ZN8unispace13us_ini_config9from_fileERKNS_10us_ustringEPS0_
错误很简单,就是us_ini_config::from_file
这个函数没有找到,说明没有将其添加到动态导出符号表中。(uds_file_storage_module.so是运行时动态加载的,所以编译的时候没有提示错误)
VC中导出符号需要使用到dllexport
,而gcc下则默认是不需要。所以这个问题很是疑惑。
考虑用的gcc
版本比较高,是不是它将-fvisibility
的参数默认设置为hidden
呢?查看了gnu的wiki之后也没有发现这个。
https://gcc.gnu.org/wiki/Visibility
这里还是有收获的,看到一段好的跨平台代码。
#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllexport))
#else
#define DLL_PUBLIC __declspec(dllexport) // 注记:实际上gcc似乎也支持这种语法。
#endif
#else
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllimport))
#else
#define DLL_PUBLIC __declspec(dllimport) // 注记:实际上gcc似乎也支持这种语法。
#endif
#endif
#define DLL_LOCAL
#else
#if __GNUC__ >= 4
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define DLL_PUBLIC
#define DLL_LOCAL
#endif
#endif
extern "C" DLL_PUBLIC void function(int a);
class DLL_PUBLIC SomeClass
{
int c;
DLL_LOCAL void privateMethod(); // Only for use within this DSO
public:
Person(int _c) : c(_c) { }
static void foo(int a);
};
然后添加了__attribute__((visibility("default")))
进行修饰,发现编译的结果没有改变(md5sun判断)。
然后又在链接的时候添加-rdynamic
参数,将所有符号都添加到动态符号表,编译结果也没有变。
在仔细查看了SConstruct
脚本之后,发现问题在于没有将对应的源文件添加到脚本中。也就是编译的时候完全就没有编译us_ini_config::from_file
所在的源文件。
这样问题就很清晰明了了,修改脚本之后重新编译就可以了。
说到这里,就该反思一下了。
这个项目早期确实是直接写的Makefile
来进行编译的,使用SOURCES = $(shell find $(SRC_DIR)$(PROJECT)/ -name "*.cpp")
来自动发现cpp文件,这本来是很好的。对于贸然使用自己不熟悉的scons
,又没有进行有效的学习,这是很不好的。
对于这个项目,还是直接使用qmake
来做跨平台的编译脚本比较好。
由一次 symbol lookup error 引发的思考的更多相关文章
- mysql: symbol lookup error: /usr/local/lib/libreadline.so.6: undefined symbol: UP
Error Symptom: when you run $mysql -u root -p command in the linux you get an error message ” mysql: ...
- centos perl: symbol lookup error: /usr/local/lib64/perl5/auto/DBD/mysql/mysql.so: undefined symbol: mysql_init
之前在安装天兔数据库监控工具lepus的时候,运行时一直报perl: symbol lookup error: /usr/local/lib64/perl5/auto/DBD/mysql/mysql. ...
- fastDfs V5.02 升级到 V5.08版本后,启动报错:symbol lookup error: /usr/bin/fdfs_trackerd: undefined symbol: g_current_time
/libfastcommon-1.0.36 # ./make.sh cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o hash.o ...
- ldd "symbol lookup error"问题解决
http://www.linuxquestions.org/questions/slackware-14/symbol-lookup-error-usr-lib-libgtk-x11-2-0-so-0 ...
- 写动态库时遇到了symbol lookup error问题
之前写TLPI上的代码一直是手动进行错误处理,感觉代码冗余量很大,最后还是决定使用书上的tlph_hdr.h,顺便回顾下动态库的创建/使用. 参考很久之前的一篇博客 linux上静态库和动态库的编译和 ...
- symbol lookup error *** , undefined symbol 错误
在重装samba过程后遇到一些问题,使用 gdb 时产生报错: gdb: symbol lookup error: gdb: undefined symbol: PyUnicodeUCS2_FromE ...
- gpg: symbol lookup error
今天使用sudo apt-get 安装包的时候,出现gpg错误,如下: gpg: symbol lookup error: /usr/local/lib/libreadline.so.6: undef ...
- symbol lookup error
今天编译代码时出现这样的错误提示: “./test: symbol lookup error: ./test: undefined symbol: ……” 问题原因是:test使用的动态库和makef ...
- symbol lookup error /usr/lib/x86_64-linux-gnu/libstdc++.so.6错误的解决办法
当出现 $ apt-get: symbol lookup error: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: undefined symbol: _ZNS ...
随机推荐
- 数学图形(1.49)Nephroid曲线
昨天IPhone6在国内发售了,我就顺手发布个关于肾的图形.Nephroid中文意思是肾形的.但是这种曲线它看上去却不像个肾,当你看到它时,你觉得它像什么就是什么吧. The name nephroi ...
- Asp.Net 控件 GridView
这两天做的作业都得用到visual studio 越来越发现其功能真心强大 前几天Asp.Net做了个界面增删查改的作业(连接数据库),用到了个组件GridView,感觉很强大 在这里小结一下(这里主 ...
- mysql-5.7.18解压版启动mysql服务
1.下载mysql社区版 2.解压到D:\Program Files 3.在D:\Program Files\mysql-5.7.18-winx64\bin下,新建文件my.ini,内容如下: [cl ...
- Openfire XMPP Smack RTC IM 即时通讯 聊天 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- MySQL配置版下载安装、配置与使用(win7x64)
http://jingyan.baidu.com/article/597035521d5de28fc00740e6.html
- jquery事件使用方法总结 (转)
http://www.cnblogs.com/cwp-bg/p/7668940.html jquery提供了许多的事件处理函数,学习前端一段时间了,下面对其总结一下,梳理一下知识点. 一.鼠标事件 1 ...
- mysql的sql分页函数limit使用 (转)
http://www.cnblogs.com/beijingstruggle/p/5631603.html mysql的sql分页函数limit使用 My sql数据库最简单,是利用mysql的LIM ...
- linux命令学习——md5sum
1.简介 MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5 全称是报文摘要算法(Message-Digest Algorithm 5),此算法对任意长度的信息逐位进行计算,产生一 ...
- MySQL数据库select语句的使用方法
select语句可 以用回车分隔 $sql="select * from article where id=1"和 $sql="select * from article ...
- idea缓存目录mac cache
IDEA如果出现卡顿,Index疯狂扫描,建议清空一下如下目录 ~/Library/Caches/IntelliJIdea2017.3 Resource nexus-maven-repository- ...