【发布时间】:2015-12-05 19:21:54
【问题描述】:
这是我遇到的错误。
-bash-4.1$ g++ strl.cpp -o -lc-
/tmp/ccRpiglh.o: In function `main':
strl.cpp:(.text+0xf): undefined reference to `plusplus'
collect2: ld returned 1 exit status
Hear 是 strl.cpp 的源代码。这是一个重复我的问题的简单示例。
strl.cpp
#include <iostream>
#include <stdlib.h>
#include "libc-.h"
using namespace std;
int main()
{
cout<<plusplus(5,2)<<'\n';
}
这里是 libc.cpp 的源代码
libc.cpp
#include <iostream>
using namespace std;
int plusplus(int a, int b)
{
return a + b;
}
libc-.h 的源代码
libc-.h
#ifndef _SCANTYPE_H_
#define _SCANTYPE_H_
#include <iostream>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
using namespace std;
int plusplus(int a, int b);
#ifdef __cplusplus
}
#endif
#endif
我正在编译以下内容:
g++ -Wall -shared -fPIC -o libc-.so libc-.cpp
g++ strl.cpp -o -lc-
g++ -Wall -shared -fPIC -o libc-.so libc-.cpp 编译没有错误。
为什么函数plusplus 是一个未定义的引用?
感谢您对我做错的任何见解。
【问题讨论】:
标签: c++ shared-libraries undefined-reference