undefined reference to错误排解方法
时间:2014-07-23 16:11 来源: 我爱IT技术网 作者:山风
通常会出现 undefined reference to `function()' 这个错误有下面这两个原因:
1、未连接正确的(静态/动态)库
2、头文件(*.h)和库(*.a / *.so / *.dll)版本不匹配。
- g++ -o test *.o -L/MyProject/lib -lApiName
在 C++ 中引用 C 的函数时,有两种作法:
a.在 C 函数声明(*.h)中用 extern C{…} 包起来。
- // file xx-api.h
- #ifndef XX_API_H
- #define XX_API_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- void function_1(const char *srcpath);
- int function_2(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
b.或是在 C++ 将 #include 用 extern C{…} 框起来。
- extern "C" {
- #include "yy-api.h"
- }
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
