【发布时间】:2011-01-01 08:23:47
【问题描述】:
我一直在尝试制作一些都依赖同一个库的应用程序,动态库是我的第一个想法:所以我开始编写“库”:
/* ThinFS.h */
class FileSystem {
public:
static void create_container(string file_name); //Creates a new container
};
/* ThinFS.cpp */
#include "ThinFS.h"
void FileSystem::create_container(string file_name) {
cout<<"Seems like I am going to create a new file called "<<file_name.c_str()<<endl;
}
然后我编译“库”
g++ -shared -fPIC FileSystem.cpp -o ThinFS.o
然后我快速编写了一个使用库的文件:
#include "ThinFS.h"
int main() {
FileSystem::create_container("foo");
return (42);
}
然后我尝试用
编译它g++ main.cpp -L. -lThinFS
但它不会编译并出现以下错误:
/usr/bin/ld: cannot find -lThinFS
collect2: ld returned 1 exit status
我认为我遗漏了一些非常明显的东西,请帮助我:)
【问题讨论】:
标签: c++ g++ dynamic-linking ld