【问题标题】:g++ undefined reference to libscrypt_scrypt (linker parameterization not the issue?)g++ 未定义对 libscrypt_scrypt 的引用(链接器参数化不是问题?)
【发布时间】:2017-01-23 21:26:01
【问题描述】:

这是我的包括:

#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h> //for snprintf
#include <libscrypt.h>
#include <sqlite3.h>
#include "generator.h" //has no dependencies

这是我的 g++ 4.2.1 命令编译错误:

# g++ -I/usr/local/include -L /usr/local/lib test.cpp generator.cpp -o test -lscrypt -lsqlite3
/tmp//cctxmw4C.o: In function `insertUser()':
test.cpp:(.text+0x607): undefined reference to `libscrypt_salt_gen(unsigned char*, unsigned long)'
test.cpp:(.text+0x6c3): undefined reference to `libscrypt_scrypt(unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned long long, unsigned int, unsigned int, unsigned char*, unsigned long)'
collect2: ld returned 1 exit status

类似的 C 代码用 GCC 编译得很好。 我不认为参数的顺序是问题 -- 我尝试了多种变体,包括移动 -I、-L 和两个 -l 标志。 scrypt 和 sqlite3 都是 C 库,尽管在 -I 和 -L 中分别具有标头和共享库,但 sqlite3 不会引发错误。

【问题讨论】:

    标签: c++ sqlite undefined-reference


    【解决方案1】:

    在这里查看解决方案。

    Using C Libraries for C++ Programs

    外部“C”{ 无效 c_function_prototype(); }

    extern "C" void c_function_prototype();
    If you have it see "The C++ Programming Language (Stoustrup) 4th Edition" p429
    

    【讨论】:

    • 哦,哇,我不知道。是用 extern "C" { ... } 包装我的#include 的首选方式,还是有一种不那么混乱的方式?
    • 是的。添加到我的答案中
    • 太好了,感谢您的帮助并祝贺您(第一个?)接受的答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    相关资源
    最近更新 更多