I am using Matlab (R2015a) together with Windows SDK 7.1 to compile a single C++ source file with Matlab's "mex" functionality. This works all fine.
However, in this C++-file, I'd like to use the GNU GMP library (arbitrary precision arithmetic/bigint), since I would appreciate some big integer calculations.
Therefore, i downloaded gmp-6.0.0 and set up the Cygwin toolchain to compile my GMP libraries for my Win-7 (64-bit) machine.
I compile/configure GMP this way in Cygwin:
$ configure --host=none-pc-cygwin --enable-alloca=malloc-notreentrant --enable-cxx --enable-static --disable-shared
$ make
$ make check
$ make install
... which gives me the header- and library files without errors or problems (gmp.h, gmpxx.h) as well as the libraries (libgmp.a, libgmpxx.a).
In my C++-program, I include the header:
#include "gmpxx.h"
... and i copy the libraries/headers to the same matlab working directory.
In my C++-code, I now try to use the GMP library, e.g. like this:
mpz_t val1;
mpz_init(val1);
I then call the matlab/mex/Windows SDK compiler (in Matlab) like so:
mex TestProgram.cpp -v libgmp.a libgmpxx.a
... which returns the following linker error:
Creating library TestProgram.lib and object TestProgram.exp
TestProgram.obj : error LNK2019: unresolved external symbol __gmpz_init referenced in function mexFunction
TestProgram.mexw64 : fatal error LNK1120: 1 unresolved externals
... And I do not know why it does this. Apparently, there are functions missing in the GMP library I compiled (?)... but why? Or is it a problem between mex and the windows SDK compiler?
Any suggestions of how to debug this? I already searched extensively, but the combination of mex and GMP is rarely used ==> little search results :-/
Edits:
Do I have to supply/link an additional library/DLL since Cygwin is used to compile?
Could it be a name mangling issue? (I also tried a purely C-based fuction/compilation, but with the exact same result)
If I compile a dynamic library with Cygwin (and supply the DLLs to matlab), I get the same linker error
Best and many thanks!
Mario
Related
I'm trying to compile a c++ mex function that I created according to the specifications given by mathworks here (Create a C++ MEX Source File). However, after following the steps of the answer in this thread to link Eclipse 4.4.2 and Matlab R2015a in a linux enviroment (old but the only one I've found about it), I get the following error:
undefined reference to `get_function_ptr' mpi_pevd_mex_f line 79, external location: C:\Program Files\MATLAB\R2021a\extern\include\MatlabDataArray\detail\ExceptionHelpers.hpp C/C++ Problem
I don't know what else is missing. I've been trying to find a solution, but nothing useful so far.
Thank you for your help.
I have found the problem. Apparently, I needed to add additional libraries to those detailed in most of the posts related to MEX files, i.e. libmex/ libmat/libmx.
Making use of the verbose mode in Matlab (mex -v MexFunction.cpp), I realized that these libraries were missing: libmwlapack, m, libmwblas, libMatlabEngine, libMatlabDataArray. After adding them, the error disappeared.
I would like to run a model is written Fortran90 under Ubuntu 14.04. I use gfortran 95 compiler (gfortran 4:4.8.2-1ubuntu6). The required netCDF libraries (netCDF C and Fortran netCDF) are installed as suggested in: http://www.unidata.ucar.edu/software/netcdf/docs/. The netcdf is built as shared library so libnetcdf.so and libnetcff.so files there are in the library directory. The libgfortran3 4.8.2-19ubuntu1 is installed for GNU fortran application linked against the shared library.
The LDFLAGS is set in the compiler_options.inc file by the following way:
INCDF=-I$(NCPATH)/include
LNCDF=-L$(NCPATH)/lib -lnetcdff -lnetcdf
LDFLAGS=$(INCDF) $(LNCDF)
When I compile the model I get the following messages:
/home/Beata/kid_a_setup/src/test_cases_2d.f90:1446: undefined reference to `_gfortran_runtime_error_at
Could someone explain me what causes the error and how I can fix it?
undefined reference to _gfortran_runtime_error_at means that the libgfortran library has not been found.
Either your system is misconfigured (can you compile, link and run a "Hello, world" program using gfortran?), or you are using the gcc command for linking instead of gfortran for linking. gcc does not know about the libgfortran library, where _gfortran_runtime_error_at is defined.
I want to compile a C++ program with a twitter library, on Linux.
I'm current using twitcurl as the twitter API library and installed g++ and all the necessary files and packages that are listed on the official website: http://code.google.com/p/twitcurl/wiki/WikiHowToUseTwitcurlLibrary
However, when I compile my program using this command g++ twitterClient.cpp -ltwitcurl, I get this error: cannot find -ltwitcurl
I also used CodeBlocks IDE to compile it but got this error: undefined reference to twitCurl::~twitCurl()
`
My code only contains a few lines:
#include <iostream>
#include "Twitter/Twitter.hpp"
using namespace std ;
int main ()
{
Twitter t ;
return 0 ;
}
I've already spent a lot of time on this but am unable to solve the problem. What should I do in order to compile the program on the command-line and CodeBlocks?
$ g++ twitterClient.cpp -ltwitcurl
cannot find -ltwitcurl
This means your compiler doesn't find the libtwitcurl.so.1. in its library directories.
First, make sure you correctly build the twitcurl library and obtained the libtwitcurl.so.1. file with something like this :
svn co http://twitcurl.googlecode.com/svn/trunk/libtwitcurl
cd libtwitcurl/
make
Secondly, make sure you put the file (or a symlink) in one of your compiler's library path :
cp libtwitcurl.so.1.0 /usr/lib/
You can check g++ library paths using the following command :
g++ --print-search-dirs | grep libraries
(/usr/lib/ is usually at the end.)
If you don't want/can't put the file in your compiler's library path, you can also tell it where to find libtwitcurl.so.1. by adding -L/path/to/twitcurl/ in the g++ options, but it is not needed if the file is already in one of the compiler's library path.
You need to specify path to twitter lib:
g++ twitterClient.cpp -L/path/to/lib/dir -ltwitcurl
I am trying to use BoostPython to write a program in C++.
My presettings are:
a. Win32 Console Application.
b. Property->C/C++->General->Additional Include Directories->C:\Python27\include;C:\Program Files\boost\boost_1_54_0;
c. Property->Linker->General->Additional Library Directions->C:\Python27\libs;
d. Microsoft Visual Studio 2012 Express Version + Python 27 + Boost 1.54
And my code is like follows:
#include <boost/python.hpp>
using namespace boost::python;
int main( int argc, char ** argv )
{
return 0;
}
As you can see, this code is with an empty main function. And I got an error message
error LNK1104: cannot open file 'boost_python-vc110-mt-gd-1_54.lib'
I checked the installation of boost ('bootstrap.bat'+'bjam.exe'), and I've searched within the folder where boost library installed for 'boost_python-vc110-mt-gd-1_54.lib', but found nothing.
I looked for some similar posts, unlike my problem, the lib file they missed was with a prefix 'lib'. On the other hand, I found this post is very similar to mine. But I found the OP made a mistake when he/her solve his/hers problem. That is, Boost is compatible with python 2.2 and its newer versions. And the rest of his answer is not helpful to me.
I guess this problem could because either I've done something wrong during installation, or I was wrong when I link the libs to my application.
Can anyone help me out of this? A detailed solution will be great. Many thanks. :)
==============================================================
EDIT:
I've reinstalled the Boost with a prebuilt binary file. Now I can link to the lib file the compiler asked for. However, new problems are raised. Now I have two new errors:
error LNK2001: unresolved external symbol __imp___Py_NoneStruct
error LNK1120: 1 unresolved externals
When I comment out the line #include <boost/python.hpp>, the above errors are gone.
I really cannot figure out the reason. Can anyone help me with this? Many thanks.
You've added the C:\Python27\libs folder to you linker settings, but that doesn't have the boost files.
You need to run boost's bjam to generate the boost library files. Lots of boost is header only, but there are some libraries which you will need to build.
When you have done that you need to add the directory to
"Property->Linker->General->Additional Library Directories"
I've found out the error is raised because the Boost library was not properly installed in my computer. Actually, the key is bjam, and it must be run to build all these necessary libraries.
I would suggest anyone else that encounter with this problem, if you don't know how to run a bjam properly, go to search for a prebuilt binary file of Boost. That could save you a lot of time.
I have built GMP for MinGW. The IDE I'm using is Code::Blocks. I don't have any problems with C functions of GMP. But I'm having problem with C++. The program I tried to run is as simple as this,
#include<iostream>
#include<gmpxx.h>
using namespace std;
main()
{
mpz_class a;
a=12345;
cout<<"value"<<a<<"\n";
return 0;
}
And the Errors I get are
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osmpz.o):osmpz.cc|| undefined reference to `__gmpz_get_str'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x1c)||undefined reference to `__gmp_asprintf_memory'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x20)||undefined reference to `__gmp_asprintf_reps'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_doprnt_integer'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_asprintf_final'|
||=== Build finished: 5 errors, 0 warnings ===|
Now, some additional data:
I don't have any problem with C functions. And also, if I remove cout<< statement the file compiles and runs fine. The problem is probably with overloaded operators.
libgmpxx.a and libgmp.a are linked with compiler. It can be seen in the error messages too...
The problem is probably with the libgmpxx.a alone. So, I built the Library again, but the files are same.
I used this tutorial build GMP with MSYS for MinGW. http://www.cs.nyu.edu/exact/core/gmp/ and http://suchideas.com/journal/2007/07/installing-gmp-on-windows/
The version of GMP I'm using is 5.0.4.
So, what I want to know is, what could be the problem? And how could it be solved?
And, if unsolvable and if you have the working files for 5.0.4 version, please share it. :(
I suspect the command to build your program specifies the libgmp* libraries in the wrong order. Make sure the libgmp.a library is specified after the libgmpxx.a library:
-lgmpxx -lgmp
If they are specified in the other order, then when pulling in dependencies from libgmpxx.a library, the libgmp.a library won't be searched.
From the ld linker's docs on the -l option:
The linker will search an archive only once, at the location where it
is specified on the command line. If the archive defines a symbol
which was undefined in some object which appeared before the archive
on the command line, the linker will include the appropriate file(s)
from the archive. However, an undefined symbol in an object appearing
later on the command line will not cause the linker to search the
archive again.
See the -( option for a way to force the linker to search archives
multiple times.
You may list the same archive multiple times on the command line.