-2
我试图使用"pngwriter"来制作png文件。我使用Ubuntu作为我的操作系统。我把这些文件放在/ home/ediamin/png /文件夹中 1.png.h,2.pngconf.h,3.pngwriter.h,4.test.cpp,5.zconf.h,6.zlib .H如何使用pngwriter编译C++程序
我TEST.CPP包含此代码
#include<iostream>
#include "pngwriter.h"
using namespace std;
int main() {
int i;
int y;
pngwriter png(300,300,0,"test.png");
for(i = 1; i < 300;i++) {
y = 150+100*sin((double)i*9/300.0);
png.plot(i,y, 0.0, 0.0, 1.0);
}
png.close();
return 0;
}
现在我想用这个命令来编译,
g++ -o test test.cpp -DNO_FREETYPE
,它给了我下面的错误,
/tmp/ccLr9Szo.o: In function `main':
test.cpp:(.text+0x30): undefined reference to `pngwriter::pngwriter(int, int, double, char const*)'
test.cpp:(.text+0x72): undefined reference to `pngwriter::filledcircle(int, int, int, double, double, double)'
test.cpp:(.text+0x7e): undefined reference to `pngwriter::close()'
test.cpp:(.text+0x8f): undefined reference to `pngwriter::~pngwriter()'
test.cpp:(.text+0xa4): undefined reference to `pngwriter::~pngwriter()'
collect2: ld returned 1 exit status
我该怎么办?请注意,我不想安装任何库文件,这就是为什么我将头文件放在同一个文件夹中的原因。
标题只包含这些函数的声明。您必须链接到包含这些函数定义的库('.a'或'.so'文件)。 – hmjd
你的代码似乎已经在编译。链接失败,这意味着你没有提供pngwriter到链接器的实现。如果你坚持不使用库,你可能(至少)需要至少编译pngwriter源代码,并链接到生成的目标文件。 –
除了您正在编译的问题之外,您可能要查找的内容被称为[静态链接](http://en.wikipedia.org/wiki/Static_library),它将所有已编译的代码包括到单个可执行文件中。 –