如何将我的C++程序与newmat类链接

How can I link my C++ program with the newmat class?

本文关键字:newmat 链接 程序 C++ 我的      更新时间:2023-10-16

我下载了newmat包,我在程序中包含了"include.h"answers"newmat.h"标头,但它无法识别名称空间newmat;如果我定义NEWMAT名称空间,甚至删除整行,我会得到几个错误,比如:

undefined reference to `BaseMatrix::t() const'

似乎没有指向该库的链接,我在谷歌上搜索了解决方案,有些人会说我已经从neewmat包中查找了.o或.a库文件,并将它们复制到lib文件夹中,其他人说我应该使用:gcc myprogram.c thebrary.o链接到库,但我在newmat包中找不到任何类型为.o或.a的文件,而且dev-c++编译器也不认为使用gcc有什么特别之处。

我是一个初学者,如果有人能帮我在程序上实现这个包,我将不胜感激。

下面是一个在Debian/Ubuuntu:中使用libnewmat10 dev包的例子

edd@max:~$ cd /tmp
edd@max:/tmp$ zcat /usr/share/doc/libnewmat10-dev/examples/example.cpp.gz > ex.cpp
edd@max:/tmp$ g++ ex.cpp -o ex -I/usr/include/newmat -lnewmat
edd@max:/tmp$ ./ex | head -25
Demonstration of Matrix package
Print a real number (may help lost memory test): 3.14159

Test 1 - traditional, bad
Estimates and their standard errors
    1.39166     0.53188 
    1.98310     0.20932 
    0.95221     0.27731 

Observations, fitted value, residual value, hat value
    2.400     1.700     8.300     7.770     0.530     0.280 
    1.800     0.900     5.500     5.818    -0.318     0.190 
    2.400     1.600     8.000     7.675     0.325     0.229 
    3.000     1.900     8.500     9.150    -0.650     0.446 
    2.000     0.500     5.700     5.834    -0.134     0.271 
    1.200     0.600     4.400     4.343     0.057     0.480 
    2.000     1.100     6.300     6.405    -0.105     0.143 
    2.700     1.000     7.900     7.698     0.202     0.153 
    3.600     0.500     9.100     9.007     0.093     0.808 
edd@max:/tmp$ 

有关更多信息,请参阅Robert的其余文档。从20多年前开始,我就经常使用newmat。但现在,我更喜欢康拉德·桑德森的《Armadillo》。

您需要查阅您的想法文档,了解如何更改链接命令或使用Makefile