Error when compiling MATIO library: "Undefined reference to 'Mat_Open'" - c++

so after building and installing the MATIO library using CMake, I am now having problems compiling it. Here's my code:
#include <iostream>
#include <matio.h>
#define tS(x) std::cout<<"\t"<<(#x)<<" == "<<(x)<<"\n"
int main(int argc, char **argv)
{
const char *fileName = argc==1?"./S.mat":argv[1] ;
mat_t *mat = Mat_Open(fileName,MAT_ACC_RDONLY);
if(mat)
{
std::cout<<"A file was opened for reading\n\tmat == "<<mat<<"\n" ;
matvar_t *matVar=0 ;
std::cout<<"Writing out the data\n\n" ;
std::cout<<"x:\n" ;
matVar = Mat_VarRead(mat, (char*)"x") ;
if(matVar)
{
int xSize = matVar->nbytes/matVar->data_size ;
const double *xData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<xSize; ++i)
{
std::cout<<"\tx["<<i<<"] = "<<xData[i]<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
}
std::cout<<"y:\n" ;
matVar = Mat_VarRead(mat, (char*)"y") ;
int ySize = matVar->nbytes/matVar->data_size ;
const double *yData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<ySize; ++i)
{
double d = yData[i] ;
std::cout<<"\ty["<<i<<"] = "<<d<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
Mat_Close(mat);
}
else
{
std::cout<<"File cannot be opened\n" ;
return 1;
}
return 0;
}
However I get the following error:
C:\WINDOWS\system32\cmd.exe /C ""C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -c "C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp" -std=c++14 -Wall -g -O0 -Wall -I/Users/RS3/matio/getopt -I/matio/include -L/matio/bin -lmatio -o ./Debug/main.cpp.o -I. -I. -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\Halton" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\quasimvnrnd"
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -o ./Debug/Test #"Test.txt" -L. -L"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -static-libgcc -static-libstdc++
./Debug/main.cpp.o: In function `main':
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:38: undefined reference to `Mat_Open'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:46: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:63: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:77: undefined reference to `Mat_Close'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Test.mk:81: Debug/Test] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe: *** [Makefile:5: All] Error 2
====4 errors, 0 warnings====
I looked for this error right and left and I know the linker can't find the library for some reason despite me having the following compiler options:
-g;-O0;-Wall;-I/Users/RS3/matio/getopt;-I/matio/include;-L/matio/bin;-lmatio
I'm using Codelite IDE.
I am not sure what I am missing and it's driving me crazy. Any help would be appreciated!

Related

Connecting CppUTest to C Interface

I'm using CppUTest to handle unit testing with my C library. However, I'm having an issue when compiling the test file.
Here's my Makefile (The CPPUTEST_HOME var is an environment variable):
CPPFLAGS += -I$(CPPUTEST_HOME)/include
CXXFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h
LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt
all:
c++ -g -Wall $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) commonTest.cpp -o commonTest $(LD_LIBRARIES)
clean:
rm -rf *.dSYM commonTest
When I run make, the following output is given:
Undefined symbols for architecture x86_64:
"_test_common_algos_commonCalloc_wrapper_c", referenced from:
TEST_common_algos_commonCalloc_Test::testBody() in commonTest-992552.o
"_test_common_algos_commonMalloc_wrapper_c", referenced from:
TEST_common_algos_commonMalloc_Test::testBody() in commonTest-992552.o
"_test_common_algos_commonRealloc_wrapper_c", referenced from:
TEST_common_algos_commonRealloc_Test::testBody() in commonTest-992552.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
To me, this seems like a linking problem. However, I don't think I've done anything wrong according to the manual:
commonTest.c:
#include "../common.h"
#include "CppUTest/TestHarness_c.h"
void *ptr = NULL;
int list[10] = {1, 2, 32, 33, 2, 5, 7, 3, 9, 34};
TEST_GROUP_C(common_algos)
{
};
TEST_C(common_algos, commonMalloc)
{
ptr = malloc_c(6);
CHECK_EQUAL_C_INT(algos_error, ALGOS_OK);
strncpy(ptr, "Hello", 5);
CHECK_EQUAL_C_STRING("Hello", ptr);
free_c(ptr);
}
TEST_C(common_algos, commonCalloc)
{
ptr = calloc_c(sizeof(int), 10);
CHECK_EQUAL_C_INT(algos_error, ALGOS_OK);
memcpy(ptr, list, sizeof(int)*10);
for (int i = 0; i < 10; i++)
CHECK_EQUAL_C_INT(list[i], ptr[i]);
free_c(ptr);
}
TEST_C(common_algos, commonRealloc)
{
ptr = malloc_c(10);
CHECK_EQUAL_C_INT(ALGOS_OK, algos_error);
memcpy(ptr, list, sizeof(int)*10);
ptr = realloc_c(ptr, 20);
CHECK_EQUAL_C_INT(ALGOS_OK, algos_error);
memcpy(ptr + 10, list, sizeof(int)*10);
for (int i = 9; i < 19; i++)
CHECK_EQUAL_C_INT(list[i-9], ptr[i]);
free_c(ptr);
}
commonTest.cpp:
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestHarness_c.h"
TEST_GROUP_C_WRAPPER(common_algos)
{
};
TEST_C_WRAPPER(common_algos, commonMalloc);
TEST_C_WRAPPER(common_algos, commonCalloc);
TEST_C_WRAPPER(common_algos, commonRealloc);
int main(int ac, char **av)
{
return RUN_ALL_TESTS(ac, av);
}
Lastly, my directory structure:
common
|______ common.c
|
|______ common.h
|
|______ test
|
|____commonTest.c
|
|____commonTest.cpp
For some context, I'm not a C++ programmer, and I'm not experienced with using CppUTest, so bear with me.
Thanks for any help and feel free to ask questions.

boost::python linking error (undefined reference to numpy::empty and numpy::detail::get_float_dtype<64>()) when using templates

I'm experiencing difficulties working with boost::python and boost::python::numpy, with python 2.7, boost 1.67.0, and Eigen3.3. My compiler is g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0.
I'm trying to convert Eigen::Matrix types to python ndarray and back (vector_list.hpp):
#ifndef VECTOR_PYLIST_HH
#define VECTOR_PYLIST_HH
#include<iostream>
#include<vector>
#include<boost/python.hpp>
#include<Eigen/Dense>
#include<typeinfo>
#include<boost/python/numpy.hpp>
namespace myutil {
template<class T>
boost::python::list to_py_list(Eigen::Matrix<T, Eigen::Dynamic,Eigen::Dynamic> matrix)
{
boost::python::list list;
boost::python::list helplist;
if (matrix.cols() > 1) {
for (int j = 0; j < matrix.cols(); j++) {
helplist = to_py_list<T>(matrix.col(j));
list.append(helplist);
}
} else {
for (int i = 0; i < matrix.rows(); i++) {
list.append(matrix(i,0));
}
}
return list;
}
template<class T>
boost::python::numpy::ndarray to_py_array(Eigen::Matrix<T, Eigen::Dynamic,Eigen::Dynamic> matrix)
{
int cols = matrix.cols();
int rows = matrix.rows();
boost::python::tuple tu = boost::python::make_tuple(rows,cols);
boost::python::numpy::dtype dtype = boost::python::numpy::dtype::get_builtin<T>();
boost::python::numpy::ndarray arr = boost::python::numpy::empty(tu, dtype);
for (int i; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = matrix(i,j);
}
}
return arr;
}
#endif
My test programme (eigen_ndarray_eigen.cpp) looks as follows:
#include<vector_list.hpp>
#include<iostream>
#include<typeinfo>
int main()
{
Py_Initialize();
np::initialize();
Eigen::Matrix<double,3,2> m;
m << 1,2,3,4,5,6;
std::cout<<m<<std::endl;
boost::python::numpy::ndarray l = myutil::to_py_array<double>(m);
Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> n = myutil::to_eigen<double>(l);
std::cout<<n<<std::endl;
return 0;
}
And my CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(myutil)
set(CMAKE_BUILD_TYPE "Debug")
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
find_package(PythonLibs 2.7 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
find_package(Boost 1.61.0 COMPONENTS python REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${Boost_INCLUDE_DIR} include)
add_executable(test_eigen_ndarray_eigen test/eigen_ndarray_eigen.cpp)
target_link_libraries(test_eigen_ndarray_eigen Eigen3::Eigen ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
I get an error when compiling:
[ 50%] Building CXX object CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o
[100%] Linking CXX executable test_eigen_ndarray_eigen
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o:In function `boost::python::numpy::ndarray myutil::to_py_array<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1>)':
/home/usr/devel/myutil/include/vector_list.hpp:70: undefined reference to `boost::python::numpy::empty(boost::python::tuple const&, boost::python::numpy::dtype const&)'
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::detail::builtin_dtype<double, false>::get()':
/usr/include/boost/python/numpy/dtype.hpp:98: undefined reference to `boost::python::numpy::dtype boost::python::numpy::detail::get_float_dtype<64>()'
collect2: error: ld returned 1 exit status
CMakeFiles/test_eigen_ndarray_eigen.dir/build.make:96: recipe for target 'test_eigen_ndarray_eigen' failed
make[2]: *** [test_eigen_ndarray_eigen] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_eigen_ndarray_eigen.dir/all' failed
make[1]: *** [CMakeFiles/test_eigen_ndarray_eigen.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
It's clearly a linking problem but I am already linking my executable against all boost libraries, and I can't figure out what might be wrong. Has anyone experienced something similar? Any tips?
Thanks for your input.
Edit: I was asked for the full error message when compiled with VERBOSE=1:
/usr/bin/cmake -H/home/usr/devel/myutil -B/home/usr/devel/myutil/build --check-build-system CMakeFiles/Makefile.cmake 1
/usr/bin/cmake -E cmake_progress_start /home/usr/devel/myutil/build/CMakeFiles /home/usr/devel/myutil/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/usr/devel/myutil/build'
make -f CMakeFiles/test_eigen_ndarray_eigen.dir/build.make CMakeFiles/test_eigen_ndarray_eigen.dir/depend
make[2]: Entering directory '/home/usr/devel/myutil/build'
cd /home/usr/devel/myutil/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/usr/devel/myutil /home/usr/devel/myutil /home/usr/devel/myutil/build /home/usr/devel/myutil/build /home/usr/devel/myutil/build/CMakeFiles/test_eigen_ndarray_eigen.dir/DependInfo.cmake --color=
Dependee "../include/vector_list.hpp" is newer than depender "CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o".
Clearing dependencies in "/home/usr/devel/myutil/build/CMakeFiles/test_eigen_ndarray_eigen.dir/depend.make".
Scanning dependencies of target test_eigen_ndarray_eigen
make[2]: Leaving directory '/home/usr/devel/myutil/build'
make -f CMakeFiles/test_eigen_ndarray_eigen.dir/build.make CMakeFiles/test_eigen_ndarray_eigen.dir/build
make[2]: Entering directory '/home/usr/devel/myutil/build'
[ 50%] Building CXX object CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o
/usr/bin/c++ -I/usr/include/python2.7 -I/home/usr/devel/myutil/include -isystem /home/usr/devel/src/eigen-git-mirror -g -o CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o -c /home/usr/devel/myutil/test/eigen_ndarray_eigen.cpp
[100%] Linking CXX executable test_eigen_ndarray_eigen
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_eigen_ndarray_eigen.dir/link.txt --verbose=1
/usr/bin/c++ -g CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o -o test_eigen_ndarray_eigen -rdynamic -lboost_python -lpython2.7
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::ndarray myutil::to_py_array<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1>)':
/home/usr/devel/myutil/include/vector_list.hpp:70: undefined reference to `boost::python::numpy::empty(boost::python::tuple const&, boost::python::numpy::dtype const&)'
CMakeFiles/test_eigen_ndarray_eigen.dir/test/eigen_ndarray_eigen.cpp.o: In function `boost::python::numpy::detail::builtin_dtype<double, false>::get()':
/usr/include/boost/python/numpy/dtype.hpp:98: undefined reference to `boost::python::numpy::dtype boost::python::numpy::detail::get_float_dtype<64>()'
collect2: error: ld returned 1 exit status
CMakeFiles/test_eigen_ndarray_eigen.dir/build.make:96: recipe for target 'test_eigen_ndarray_eigen' failed
make[2]: *** [test_eigen_ndarray_eigen] Error 1
make[2]: Leaving directory '/home/usr/devel/myutil/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/test_eigen_ndarray_eigen.dir/all' failed
make[1]: *** [CMakeFiles/test_eigen_ndarray_eigen.dir/all] Error 2
make[1]: Leaving directory '/home/usr/devel/myutil/build'
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
`'
I checked some answers regarding similar problems (here). Apparently boost_numpy doesn't call the right libraries automatically and sometimes you have to include them manually:
#define BOOST_LIB_NAME "boost_numpy"
#include <boost/config/auto_link.hpp>
I tried this but it didn't work for me...

make: Nothing to be done for 'all'

I have only 2 files in my folder - Gnuplot_example.cpp and Makefile.
Gnuplot_example.cpp
#include "Snap.h"
int main(int argc, char* argv[]) {
TIntH expCount, PoissonCount;
TRnd a;
double binSize=0.1;
//exponential distribution
for (int i=0; i<10000; ++i)
{
double num=a.GetExpDev(1);
expCount.AddDat((int)(num/binSize))++;
}
//Poisson distribution
for (int i=0; i<10000; ++i)
{
double num=a.GetPoissonDev(10);
PoissonCount.AddDat((int)(num/binSize))++;
}
expCount.Sort(true,true);
PoissonCount.Sort(true,true);
{
TVec<TPair<TFlt, TFlt > > XY1, XY2;
for (int i=0; i<expCount.Len(); ++i)
XY1.Add(TFltPr(expCount.GetKey(i)*binSize, expCount[i]+0.0));
for (int i=0; i<PoissonCount.Len(); ++i)
XY2.Add(TFltPr(PoissonCount.GetKey(i)*binSize,PoissonCount[i]+0.0));
TGnuPlot Gp("distribution", "Exponential and Poisson Distribution");
Gp.AddPlot(XY1, gpwLinesPoints, "Exponential");
Gp.AddPlot(XY2, gpwLinesPoints, "Poisson");
Gp.SetXYLabel("value", "count");
Gp.SavePng(); //or Gp.SaveEps();
}
return 0;
}
Makefile
#
# Makefile for non-Microsoft compilers
#
all: $(Gnuplot_example)
# COMPILE
$(Gnuplot_example): $(Gnuplot_example).cpp $(DEPH) $(DEPCPP) $(EXSNAP)/Snap.o
$(CC) $(CXXFLAGS) -o $(Gnuplot_example) $(Gnuplot_example).cpp $(DEPCPP) $(EXSNAP)/Snap.o -I$(EXSNAP) -I$(EXSNAPADV) -I$(EXGLIB) -I$(EXSNAPEXP) $(LDFLAGS) $(LIBS)
$(EXSNAP)/Snap.o:
make -C $(EXSNAP)
clean:
rm -f *.o $(Gnuplot_example) $(Gnuplot_example).exe
rm -rf Debug Release
When I am using command 'make' in this folder, it says:
make: Nothing to be done for 'all'.
and there is no object file created. I have gone through other answers and I made sure to use tab in rules instead of spaces. I am new to this. I am not getting what is wrong.
Thanks for any Help!!

Undefined reference to function error

I have received a .h file to be used as part of a c++ program. I tried every method to link it, yet the undefined reference error is occurring. I'm using NetBeans in ubuntu.
The .h file contains the functions I'm trying to use. And yet the compiler is unable to find the function.
Here's a snippet of the fwlib32.h file since it is too big to insert the whole file:
FWLIBAPI short WINAPI cnc_allclibhndl3( const char *, unsigned short, long, unsigned short * );
FWLIBAPI short WINAPI cnc_upstart3( unsigned short, short, long, long ) ;
FWLIBAPI short WINAPI cnc_upstart3_f( unsigned short, short, char *, char * ) ;
FWLIBAPI short WINAPI cnc_statinfo( unsigned short, ODBST * ) ;
FWLIBAPI short WINAPI cnc_upload3( unsigned short, long *, char * ) ;
FWLIBAPI short WINAPI cnc_upend3( unsigned short ) ;
FWLIBAPI short WINAPI cnc_freelibhndl( unsigned short ) ;
Here's my program file:
#include "fwlib32.h"
#include<pthread.h>
#include<stdio.h>
#include<string.h>
#define BUFSIZE 1280
static unsigned short H;
struct conn_data
{
char ip[100];
short prt;
long tmo;
long pnum;
};
void conn(char *ipadd, short port, long tmout )
{
unsigned short h;
short ret;
ODBST buf;
ret = cnc_allclibhndl3( ipadd, port, tmout, &h ) ;
if ( !ret ) {
cnc_statinfo( h, &buf ) ;
H=h;
}
else
printf( "ERROR!(%d)\n", ret ) ;
}
short upld( long prgnum )
{
unsigned short h=H;
char buf[BUFSIZE+1] ;
short ret ;
long len;
ret = cnc_upstart3( h, 0, prgnum, prgnum ) ;
if ( ret ) return ( ret ) ;
do {
len = BUFSIZE ;
ret = cnc_upload3( h, &len, buf ) ;
if ( ret == EW_BUFFER ) {
continue ;
}
if ( ret == EW_OK ) {
buf[len] = '\0' ;
printf( "%s", buf ) ;
}
if ( buf[len-1] == '%' ) {
break ;
}
} while ( ret == EW_OK ) ;
ret = cnc_upend3( h ) ;
return ( ret ) ;
pthread_exit(&ret);
}
void* start_thread(void * dat)
{
struct conn_data *data;
data = (struct conn_data *)dat;
conn(data->ip, data->prt, data->tmo);
upld(data->pnum);
}
int main()
{
struct conn_data data;
char ip[100];
short prt;
long tmo,pnum;
pthread_t thread1;
int *ptr;
printf("\nEnter the IP address\n");
scanf("%s",ip);
strcpy(data.ip,ip);
printf("\nEnter the port number\n");
scanf("%hd",&prt);
data.prt=prt;
printf("\nEnter the timeout period in seconds\n");
scanf("%ld",&tmo);
data.tmo=tmo;
printf("Enter the program number\n");
scanf("%ld",&pnum);
data.pnum=pnum;
pthread_create(&thread1, NULL, start_thread, (void*)&data);
pthread_join(thread1, (void **) &ptr);
cnc_freelibhndl( H ) ;
return 0;
}
and these are the contents of the compiler window in NetBeans:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/amit1
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
CLEAN SUCCESSFUL (total time: 56ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/amit1
make[2]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/connect.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/connect.o.d -o build/Debug/GNU-Linux-x86/connect.o connect.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/amit1 build/Debug/GNU-Linux-x86/connect.o -lpthread
build/Debug/GNU-Linux-x86/connect.o: In function `conn(char*, short, long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:22: undefined reference to `cnc_allclibhndl3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:24: undefined reference to `cnc_statinfo'
build/Debug/GNU-Linux-x86/connect.o: In function `upld(long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:37: undefined reference to `cnc_upstart3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:41: undefined reference to `cnc_upload3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:53: undefined reference to `cnc_upend3'
build/Debug/GNU-Linux-x86/connect.o: In function `main':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:88: undefined reference to `cnc_freelibhndl'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/amit1] Error 1
make[2]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 220ms)
I looked at other similar questions and tried to add the library file in the project properties option, or to just create a -lfwlib32 option in the g++ statement. None of them caused any change. The program would still not build. Can anyone please help me?
turns out the libfwlib32.so file is for 32 bit systems, while mine is a 64 bit system. i'll try to run it in the 32 bit system compatibilty

Another "undefined reference" error when linking boost libraries

I've seen several other posts that deal with this exact same issue. However, none of their solutions seem to work for me. I am compiling the following code:
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/timer/timer.hpp>
using namespace boost::numeric::ublas;
int main(){
matrix<double> mat1 (3,3);
matrix<double> mat2 (3,3);
matrix<double> mat3 (3,3);
unsigned k=0;
for(unsigned i = 0; i < mat1.size1(); ++i){
for(unsigned j = 0; j < mat1.size2(); ++j){
mat1(i,j) = k;
mat2(i,j) = 2*k++;
}
}
k=0;
if(1){
boost::timer::auto_cpu_timer t;
while(k<1000){
mat3 = prod(mat1,mat2);
k++;
}
}
return 0;
}
I am compiling from the command line using:
$ g++ matrix_test.cpp -o matrix_test -lboost_system -lboost_timer
and receiving the following error:
usr/lib/gcc/i686-redhat-linux/4.7.0/../../../libboost_timer.so:
undefined reference to `boost::chrono::steady_clock::now()'
collect2: error: ld returned 1 exit status
If I add -lboost_chrono when I compile, I get this error:
/usr/lib/gcc/i686-redhat-linux/4.7.0/../../../libboost_chrono.so:
undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
I can trace clock_gettime to sys/time.h. Unfortunately, I cannot find a corresponding .so file to link to. What am I missing here?
You must add -lrt to your link libraries
g++ matrix_test.cpp -o matrix_test -lboost_system -lboost_timer -lboost_chrono -lrt
Update (2016-08-31)
This still seems to be an issue. When you lookup man clock_gettime, this leads to the solution (-lrt), but it also says
Link with -lrt (only for glibc versions before 2.17).
So when your glibc is newer, your problem might be something else.
Add -lrt to your g++ invocation – clock_gettime is in librt.so.