I am new to using libraries and I am having some trouble with lapack++ and getting it to work. I will explain what I have done and tried so far.
First I installed BLAS and LAPACK and that went fine. I now have installed LAPACK++ version 2.5.2 (http://lapackpp.sourceforge.net/) so I can call various linear algebra routines in C/C++. After I configure, make and then make install it places all the C/C++ header files in /usr/local/include/lapackpp/ some of which are..
arch.h
bmd.h
gmf.h
lapackc.h
lautil.h
spdmd.h
ultgmd.h
bfd.h
...
and also the following files in /usr/local/lib
liblapackpp.la
liblapackpp.so
liblapackpp.so.14
liblapackpp.so.14.2.0
Now if I try to compile using g++ the simple code of
#include <lapackpp/lapackpp.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
I get the following output...
In file included from /usr/local/include/lapackpp/lapackc.h:14,
from /usr/local/include/lapackpp/lapack.h:10,
from /usr/local/include/lapackpp/lapackpp.h:16,
from test.cpp:1:
/usr/local/include/lapackpp/lacomplex.h:45:23: error: laversion.h: No such file or directory
/usr/local/include/lapackpp/lacomplex.h:48:17: error: f2c.h: No such file or directory
In file included from /usr/local/include/lapackpp/lapackpp.h:47,
from test.cpp:1:
/usr/local/include/lapackpp/latmpl.h:36:22: error: lafnames.h: No such file or directory
I solved this problem by writing the location of the header file explicitly in the header file that was causing trouble.
Eg. I replaced
#include
with
#include
After doing this my code compiles fine.
Now if I try to compile the code
#include <cstdlib>
#include <iostream>
#include <lapackpp/lapackpp.h>
using namespace std;
int main(int argc, char** argv) {
LaGenMatDouble A(5,5);
cout << "This is a test." << endl;
return 0;
}
by typing
g++ test.cpp -o test -I usr/local/include/lapackpp
I get the following errors
/tmp/ccAq6nkP.o: In function `main':
test.cpp:(.text+0x22): undefined reference to `LaGenMatDouble::LaGenMatDouble(int, int)'
test.cpp:(.text+0x4f): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
test.cpp:(.text+0x67): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
collect2: ld returned 1 exit status
(Info on LaGenMatDouble is here )
which suggests I may be linking to the library wrong?
After some googling I realised that I needed to link to the header files using -I and the shared library by -L and the library itself by -llapackpp, so then I typed
g++ test.cpp -o test -I usr/local/include/lapackpp -L usr/local/lib -llapackpp
which compiled the code, now when I ran the program by typing ./test I go the error
./test: error while loading shared libraries: liblapackpp.so.14: cannot open shared object file: No such file or directory
and now I am confused.
I am unsure if this has anything to do with the problem but when I type
pkg-config lapackpp --libs
I get
Package lapackpp was not found in the pkg-config search path.
Perhaps you should add the directory containing `lapackpp.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lapackpp' found
The same happens for lapack and blas too.
I am unsure what to do. Any help would be very much appreciated, thanks!
Linking goes fine because you tell to the linker where the library is, but execution failed because the loader doesn't know anything about the location of your libraries (you can check that performing ldd yourapp, which shows the library needed by your application).
Usually, you can solve that by telling to the loader where the library is through the variable LD_LIBRARY_PATH, but it is a crude tool. A different solution is to encode that instruction directly in the executable, as described here, or simply to link statically your application using the switch -static
If you're after a C++ library that wraps LAPACK (and/or BLAS), you might be better off using a more modern library such as Armadillo. Besides using LAPACK as a backend for solvers and matrix factorizations, it uses expression templates to speed up operations.
Related
I compiled the library for the C++ API for TensorFlow Lite (r1.97) using the script ${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/build_rpi_lib.sh following the steps suggested at this official page (Native Compiling, downloading the necessary libraries), where ${TENSORFLOW_ROOT} is the root folder where I cloned the repository.
I am trying to compile this simple test.cpp program:
#include <memory>
#include "tensorflow/lite/interpreter.h"
int main(void)
{
std::unique_ptr<tflite::Interpreter> interpreter(new tflite::Interpreter);
}
using the command:
gcc-6 test.cpp -I${TENSORFLOW_ROOT} -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/eigen -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/protobuf/src -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads -L${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/gen/rpi_armv7l/lib -lstdc++ -ldl -ltensorflow-lite
The list of includes was suggested in the Integrating TensorFlow libraries page (specifically from the section iOS). Compilation fails with the following error related to the inclusion of Eigen:
${TENSORFLOW_ROOT}/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory
#include "unsupported/Eigen/CXX11/Tensor"
I found several links where an apparently similar problem is discussed (such as this one), but the proposed solutions involve using references to the TensorFlow python package which is something that is not possible in my case (and it feels quite patchy - I am not considering using python for this project).
I also tried using a different include path to Eigen (e.g. ${TENSORFLOW_ROOT}/third_party/eigen3):
gcc-6 test.cpp -I${TENSORFLOW_ROOT} -I${TENSORFLOW_ROOT}/third_party/eigen3 -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/protobuf/src -I${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads -L${TENSORFLOW_ROOT}/tensorflow/lite/tools/make/gen/rpi_armv7l/lib -lstdc++ -ldl -ltensorflow-lite
and also this causes Eigen related compilation errors of this sort:
...
${TENSORFLOW_ROOT}/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42: error: #include nested too deeply
#include "unsupported/Eigen/CXX11/Tensor"
...
${TENSORFLOW_ROOT}/third_party/eigen3/Eigen/Core:1:22: error: #include nested too deeply
#include "Eigen/Core"
...
Any suggestions on how to solve this issue? What is the right set of include paths?
Turns out I was including the wrong folder. Instead of ${TENSORFLOW_ROOT}/tensorflow/contrib/makefile/downloads/eigen or ${TENSORFLOW_ROOT}/third_party/eigen3, the right one is ${TFLITE_ROOT}/tensorflow/lite/tools/make/downloads/eigen.
I am still puzzled by the number of eigen folders inside the repository:
find . -name "eigen*" -type d
./third_party/eigen3
./tensorflow/lite/tools/make/downloads/eigen
I am trying to switch to Windows environment from Linux, but find it a very hard path.
This time I wanted to test if I can work with boost library.
I had problems with compiling boost on windows, so I downloaded precompiled version. I unpacked everything and tested positively that I can compile the header-only librariers.
Then I copied some simple boost::asio example. I set up everything in Eclipse. Compilation went fine, but during linking I got 'undefined reference' problem to 'boost::system' internal stuff.
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
So I added '-lboost_system', as well as the path to the libraries directory, to my linking options. But this did not help.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -lboost_system
I checked the libraries directory and found there is a bunch of files containing 'boost_system' in the name. They are:
libboost_system-vc140-mt-1_62.lib
libboost_system-vc140-mt-gd-1_62.lib
libboost_system-vc140-mt-s-1_62.lib
libboost_system-vc140-mt-sgd-1_62.lib
libboost_system-vc140-s-1_62.lib
libboost_system-vc140-sgd-1_62.lib
I did not know which I should use. I tried adding 'libboost_system-vc140-mt-1_62' to the linking options, I tried all other files, I tried renaming the files to the linux pattern 'libboost_system.a', but nothing worked.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -llibboost_system-vc140-mt-1_62 -llibboost_system-vc140-mt-gd-1_62 -llibboost_system-vc140-mt-s-1_62 -llibboost_system-vc140-mt-sgd-1_62 -llibboost_system-vc140-s-1_62 -llibboost_system-vc140-sgd-1_62
What am I doing wrong here?
Please help...
YotKay
I solved it myself with the help of a comment from this post: boost asio example compilation error
It looks like the precompiled version of Boost is created with Visual Studion and is NOT COMPATIBLE with G++. I if I decided to install MinGW then I cannot use the precompiled version of boost, but must compile it myself using g++.
I did that.
Now I have libraries compiled with G++.
I specify the path to the boost system library like that:
c:\Users\jacek\cpp\boost_1_62_0\libraries\boost\bin.v2\libs\system\build\gcc-mingw-6.2.0\debug\link-static\
and add this option:
-lboost_system-mgw62-d-1_62
Now the problem with boost::system disappears. However, another one pops up with boost asio, but luckily the answer is here: MinGW linker error: winsock
The example works fine now on my Windows 10 laptop.
#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <chrono>
#include <iostream>
using namespace boost::asio;
int main()
{
io_service ioservice;
steady_timer timer{ioservice, std::chrono::seconds{3}};
timer.async_wait([](const boost::system::error_code &ec)
{ std::cout << "3 sec\n"; });
ioservice.run();
}
I know there are several questions like this, no answer I have found so far seems to solve my problem.
I am using eclipse.
I coded something in the main function, and it worked fine.
I then an external function with the code in the main and now I get funny mistakes.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <random>
#include <ctime>
#include <cstdlib>
using namespace std;
using namespace cv;
void createSaltandPepper();
int main(int argc, char** argv) {
createSaltandPepper();
return 0;
}
No, as I am trying not to give to extensive an example again, here is the outside of the function:
void createSaltandPepper() {
//mycode
}
At least it does not seem to be a spelling mistake.
However, the error is:
make all
make: *** No rule to make target 'SaltPepper.o', needed by 'Display'.
I do wonder why it is trying to make a tagert called SaltPepper.o if my function is called createSaltandPepper.
Can somebody help me?
Edit: I did not conciously create a makefile, as I said I am working with eclipse.
And again, the code works fine as long as it is inside the main function instead of inside createSaltandPepper().
My file is called DisplayImage.cpp, the code above is in this file, including the function createSaltandPepper();
The only two function in this file are the main function and createSaltandPepper();
There are no other source files in the project.
I am sorry if I come across as rather stupid: I am a Java programmer and have not a clue about makefiles and such.
See this screenshot:
I now created a new project and added my old file into it, this time calling it Display.cpp
"build all" resulted in an error in subdir.mk which reads:
subdir.mk:18: recipe for target 'Display.o' failed
make: *** [Display.o] Error 1
The complete Error message for the build is as follows:
make all
Building file: ../Display.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0-std=c++11 -MMD -MP -MF"Display.d" -MT"Display.d" -o"Display.o" "../Display.cpp"
subdir.mk:18: recipe for target 'Display.o' failed
g++: error: argument to ‘-fmessage-length=’ should be a non-negative integer
make: *** [Display.o] Error 1
Update
I switched to Netbeans.
It now works.
First, this error has nothing to do with compilers, this error message is produced by the build system (make in your case). Basically, eclipse seems to call make, which figures out what are dependencies between files and which of them need recompiling and in turn calls the compiler to compile them. Every C++ source file is then compiled to an object file .o (typically with the same name: SaltPepper.cpp -> SaltPepper.o). Then all the object files are linked together with the libraries to form the final executable.
This particular error message tells you that your executable is specified to depend on the object file SaltPepper.o, but the build system does not know how to produce it. Most likely there is no corresponding SaltPepper.cpp file. So check if such file exists. If not, check the settings of your project (or the Makefile if you created it manually) and see if all the cpp filenames are specified correctly. You should add all the cpp files with your code to the project, and remove all the extraneous cpp files.
Update: Note that build system operates on the file level. It does not know anything about functions etc., only source files. Maybe this is the source of the confusion.
It's been days searching for a way to get the MySQL C API working with a MinGW compiler, and frankly I have to say this is getting very frustrating.
I'm trying to compile the minimal example:
#include <my_global.h>
#include <mysql.h>
int main(int argc, char **argv)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
exit(0);
}
and I keep on getting:
[Linker Error] undefined reference to `mysql_get_client_info#0'
I have compiled the libraries (including libmysql.a which contains mysql_get_client_info) and properly linked them, included all include and lib directories properly. Basiacly, everything is done by the letter according not only to the tutorials but also to forum posts which dealt specifically with this problem.
Now, what am I doing wrong?
Thanks
Having looked at your make-file, it would appear you've forgotten the mysql flags, required for your code to compile. On linux, you'd have to include the output of mysql_config --cflags --libs in the make file.
Add those to your makefile and the code should compile just fine.
I've been trying to use MySQL and C++ together but can't seem to get started as I cannot seem to gain usage of the relevant libraries.
I am on Win7 using MinGW compiler and working in Netbeans.
I have the code:
#include <cstdlib>
#include <iostream>
#include <my_global.h>
#include <mysql.h>
using namespace std;
int main(int argc, char **argv)
{
cout << "MySQL client version: " << mysql_get_client_info();
}
But netbeans cannot find my_global.h or mysql.h.
In properties of the project I've linked to the library libmysql.dll.
Also present in the same directory is mysqlclient.lib but I can't find a way to link to that as the NetBeans linker doesn't seem to register that extension type.
Any help would be greatly appreciated.
C
---PROGRESS
I went into NetBeans' Properties->Build->C++ section and added the include directory of my MySQL installation in the 'Include Directories' section. This has solved the above issue of not finding my_global.h or mysql.h but now it cannot find crtdbg.h...
Actually had crtdbg.h in an old Visual Studio installation, moved it and all the other .h files there over to my MinGW includes folder. Seems to find the .hs now but fails with loads of errors, probably an issue with the Visual Studio .h files not being compatible with MinGW. Back to the drawing board.
Set the include directories, mate. It is under Tools->Options->C++->Code Assistance. Add the path where the my_global.h is.
See this forum post.
I'm not sure in Windows, but in Linux you can use the mysql_config tool to get the correct flags to compile a client application:
For compiling:
$ mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
And for linking:
$ mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
Now, if you are using MinGW, options should be similar, probably dropping the *_LINUX ones.
My bet is that you are simply missing the -I<path_to_include_dir> bit.