我一直試圖做一些應用,這都依賴於相同的庫,和動態庫是我的第一個想法:所以我開始寫的「庫」:爲什麼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