关于 c : 共享对象文件中的未定义符号 | 珊瑚贝

Undefined symbol in shared object file


我使用以下代码编译了我的代码:

1
gcc c O3 fPIC fnortti fnoimplicittemplates Wnodeprecated I. I/rw/include/ Exotic.C o RBCExotic.o

当我尝试使用 \\’RBCExotic.o\\’ 文件时,我收到以下错误。

1
loading error /home/rw/rw_lib/Exotics.so: undefined symbol: _ZN5ArrayIPKvE4sizeEibbb

当我使用 nm 对代码进行解码时,出现错误的行是:

1
U Array<void const*>::size(int, bool, bool, bool)

但是,这个 \\’size\\’ 函数是在 \\’/rw/include/\\’ 内的头文件中定义和实现的:

1
2
3
4
5
6
template <class T>
int
Array< T >::size(int n, bool reduceMem, bool copyData, bool delData)
{
    return _size(n, reduceMem, copyData, delData);
}

并且\\’_size\\’也定义在它的正下方。

我是否错误地编译了这段代码?还有其他可能的问题,这可能是某种红鲱鱼?


-fno-implicit-templates 表示”不要实例化我使用的模板,我将通过提供显式实例化手动执行此操作。”

所以你对编译器撒了谎。你告诉它不要为了提供所需的符号而实例化 Array<T>::size 函数模板,所以它按照你的要求做了,但你没有遵守协议。

最好的解决方案是停止使用该选项,让编译器自动执行正确的操作。当您使用 Array<void const*>::size(int, bool, bool, bool) 时,它将在头文件中实例化通用定义并提供缺少的符号。

有关更多信息,请参阅 GCC 手册,尽管该页面非常过时并且应该忽略 -frepo 是最佳选项的位。最好的选择是第三个。

如果您真的非常想使用该选项,则需要为您使用的每个模板提供显式实例化(这是 GCC 文档中的第二个选项)。在 .C 文件(不是标题)中定义 Array<void const*> 的显式实例化,如下所示:

1
template class Array<void const*>;

或者对于单个函数:

1
template int Array<void const*>::size(int, bool, bool, bool);

我看到你包括头文件(-I)。那是Mac吗?我不认识路径。
也许这可以帮助你:

clang -stdlib=libc 导致未定义的引用

我看过

1
g++ std=c++11 your_file.cpp o your_program I(as necessary)


在别处使用。


来源:https://www.codenong.com/25753308/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9291.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?