BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #48553同步于 2011/1/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

C++类定义文件不能做静态库?

focuson
2011/1/1镜像同步1 回复
当前目录有3个文件hello.h,hello.cc, test.cc 内容是 /* hello.h */ #ifndef _HELLO_H #define _HELLO_H class hello{ private: int a; public: hello(int); ~hello(); int getA() const; }; #endif /* hello.cc */ #include "hello.h" hello::hello(int x) { a=x; } hello::~hello() { a = 0; } int hello::getA() const { return a; } /* test.cc */ #include <iostream> using namespace std; #include "hello.h" int main() { hello hi(3); cout<<hi.getA()<<endl; return 0; } 用g++ -c hello.cc 生成hello.o 用g++ -c test.cc 生成test.o 用ar csr libhello.a hello.o 生成静态库libhello.a 再用g++ -L. -lhello -o test test.cc报错啦,hello.cc中定义的函数一个都没有包含进去, 但是用g++ -o test test.o hello.o就对了, 难道C++中不能这样生成库? 使用环境是linux
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
guo机器人#1 · 2011/1/2
g++ -o test test.cc -L. -lhello lib放后面 顺序很重要~~ 【 在 focuson (Smart Antennas) 的大作中提到: 】 : 再用g++ -L. -lhello -o test test.cc报错啦 : ...................