我一直试图做一些应用,这都依赖于相同的库,和动态库是我的第一个想法:所以我开始写的“库”:为什么g ++没有链接到我创建的动态库?
/* 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
我想我失去了一些东西很明显,请帮我:)
感谢前缀的lib在前面失踪( .o而不是.so只是一个错字):) – lazlow 2010-01-04 18:41:03