linux下连接静态库的问题
用静态库封装类调用时出错,不明白问题出在哪里,请高手指点。简单示例程序:
#ifndef __HTTP_H__
#define __HTTP_H__
#include <stdio.h>
class Http
{
public:
void InitHttp();
void CloseHttp();
int PrintHttp(const char* str);
};
#endif
cpp文件:
#include "http.h"
void Http::InitHttp()
{
}
void Http::CloseHttp()
{
}
int Http::PrintHttp(const char* str)
{
printf("%s\n",str);
return 1;
}
main.cpp
#include "http.h"
int main()
{
Http* m_http = new Http();
m_http->PrintHttp("http");
delete m_http;
return 1;
}
先生成目标文件: g++ -c http.cpp
生成静态库: ar cr libmyhttp.a http.o
这两步什么问题,都已经生成,连接后编译:
g++ -o test main.cpp -L.-lmyhttp
出现错误:/tmp/cc6cxeOn.o: In function `main':
main.cpp:(.text+0x20): undefined reference to `Http::PrintHttp(char const*)'
collect2: ld 返回 1
本人刚接触linux下的编程,请高手指点。