bash: ./main.o cannot execute binary file Exec format error - c++

I have set up a ubuntu virtual machine on windows using virtual box.
I am trying to run a C++ project. The make file looks like this
CC = g++ -O2 -Wno-deprecated
tag = -i
ifdef linux
tag = -n
endif
test.out: Record.o Comparison.o ComparisonEngine.o Schema.o File.o DBFile.o y.tab.o lex.yy.o test.o
$(CC) -o test.out Record.o Comparison.o ComparisonEngine.o Schema.o File.o DBFile.o y.tab.o lex.yy.o test.o -lfl
main: Record.o Comparison.o ComparisonEngine.o Schema.o File.o y.tab.o lex.yy.o main.o
$(CC) -o main Record.o Comparison.o ComparisonEngine.o Schema.o File.o y.tab.o lex.yy.o main.o -lfl
test.o: test.cc
$(CC) -g -c test.cc
main.o: main.cc
$(CC) -g -c main.cc
Comparison.o: Comparison.cc
$(CC) -g -c Comparison.cc
ComparisonEngine.o: ComparisonEngine.cc
$(CC) -g -c ComparisonEngine.cc
DBFile.o: DBFile.cc
$(CC) -g -c DBFile.cc
File.o: File.cc
$(CC) -g -c File.cc
Record.o: Record.cc
$(CC) -g -c Record.cc
Schema.o: Schema.cc
$(CC) -g -c Schema.cc
y.tab.o: Parser.y
yacc -d Parser.y
sed $(tag) y.tab.c -e "s/ __attribute__ ((__unused__))$$/# ifndef __cplusplus\n __attribute__ ((__unused__));\n# endif/"
g++ -c y.tab.c
lex.yy.o: Lexer.l
lex Lexer.l
gcc -c lex.yy.c
clean:
rm -f *.o
rm -f *.out
rm -f y.tab.c
rm -f lex.yy.c
rm -f y.tab.h
After running the make command I get a bunch of warnings like
g++ -O2 -Wno-deprecated -g -c Record.cc
g++ -O2 -Wno-deprecated -g -c Comparison.cc
g++ -O2 -Wno-deprecated -g -c ComparisonEngine.cc
g++ -O2 -Wno-deprecated -g -c Schema.cc
Schema.cc: In constructor ‘Schema::Schema(const char*, const char*)’:
Schema.cc:46:9: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:58:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:84:9: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:91:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:95:11: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:106:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:114:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
Schema.cc:118:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf (foo, "%s", space);
~~~~~~~^~~~~~~~~~~~~~~~~~
g++ -O2 -Wno-deprecated -g -c File.cc
File.cc: In member function ‘void File::GetPage(Page*, off_t)’:
File.cc:186:7: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
read (myFilDes, bits, PAGE_SIZE);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
File.cc: In member function ‘void File::AddPage(Page*, off_t)’:
File.cc:206:10: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
write (myFilDes, &foo, sizeof (int));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
File.cc:223:8: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
write (myFilDes, bits, PAGE_SIZE);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
File.cc: In member function ‘void File::Open(int, char*)’:
File.cc:258:8: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
read (myFilDes, &curLength, sizeof (off_t));
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
File.cc: In member function ‘int File::Close()’:
File.cc:276:8: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
write (myFilDes, &curLength, sizeof (off_t));
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
g++ -O2 -Wno-deprecated -g -c DBFile.cc
yacc -d Parser.y
sed -i y.tab.c -e "s/ __attribute__ ((__unused__))$/# ifndef __cplusplus\n __attribute__ ((__unused__));\n# endif/"
g++ -c y.tab.c
y.tab.c: In function ‘int yyparse()’:
y.tab.c:1427:35: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
yyerror (YY_("syntax error"));
^
y.tab.c:1571:35: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
yyerror (YY_("memory exhausted"));
^
lex Lexer.l
gcc -c lex.yy.c
g++ -O2 -Wno-deprecated -g -c test.cc
g++ -O2 -Wno-deprecated -o test.out Record.o Comparison.o ComparisonEngine.o Schema.o File.o DBFile.o y.tab.o lex.yy.o test.o -lfl
All files compile generating respective .o files except the main.cc. So I compile it using this command
g++ -O2 -Wno-deprecated -g -c -o main.o main.cc
Now the main.o file compiles and main.o is generated
I then run it using ./main.o and get Permission denied
So I get rid of this error by chmod 755 ./*
Now running the main.o gives this error
bash: ./main.o cannot execute binary file Exec format error
Through my research I found out that this error is because of the mismatch in arhitecture and file type.
file main.o outputs x86-64 and uname -m outputs x86_64
I cannot figure out the problem.
Any help would be greatly appreciated! Thank you!

You are trying to execute an object file. Object files like main.o are not executable. They only contain part of the code required to form an exectuable.
You need to run main (or maybe test.out), which is the actual executable.
The permission warnings were telling you the same thing (that main.o is not executable), but you overwrote that with chmod.
main should be created by make assuming there are no compilation/linking errors if you use make main or test.out if you use make or make test.out. The linker invocation is given in the main:/test.out: target of the Makefile. If make generates compiler or linker errors, then repeating the same commands manually is not going to fix it. Fix the code or Makefile instead.
Also note that the warnings/errors are there for a reason. Since C++11, you are not allowed to cast string literals to char*, only to const char*. This was deprecated already in C++03. Circumventing that rule is only going to cause you trouble in the future. Fix your code instead of adding -Wno-deprecated.

Related

Build of nixos.avrgcclibc fails on NixOS

I am trying to install avr-gcc-libc on NixOS, but run into a build error.
I try to install with the command
nix-env -iA nixos.avrgcclibc
The output this produces is very long and terminates with
g++ -c -DIN_GCC_FRONTEND -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -Icp -I../../gcc -I../../gcc/cp -I../../gcc/../include -I../../gcc/../libcpp/include -I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc/../libbacktrace -o cp/except.o
-MT cp/except.o -MMD -MP -MF cp/.deps/except.TPo ../../gcc/cp/except.c
In file included from ./tm.h:18:0,
from ../../gcc/cp/except.c:27:
../../gcc/config/elfos.h:102:21: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
^
../../gcc/config/elfos.h:170:24: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
^
In file included from ../../gcc/cp/except.c:1023:0:
cfns.gperf: In function 'const char* libc_name_p(const char*, unsigned int)':
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
cfns.gperf:26:14: note: 'const char* libc_name_p(const char*, unsigned int)' previously declared here
cfns.gperf: At global scope:
cfns.gperf:26:14: warning: inline function 'const char* libc_name_p(const char*, unsigned int)' used but never defined
make[2]: *** [Makefile:1064: cp/except.o] Error 1
make[2]: Leaving directory '/tmp/nix-build-avr-gcc-libc.drv-0/gcc-5.3.0/obj-avr/gcc'
make[1]: *** [Makefile:4094: all-gcc] Error 2
make[1]: Leaving directory '/tmp/nix-build-avr-gcc-libc.drv-0/gcc-5.3.0/obj-avr'
make: *** [Makefile:852: all] Error 2
builder for ‘/nix/store/0ypaa4x9x0lsyygciasw9m1v4jswgm49-avr-gcc-libc.drv’ failed with exit code 2
error: build of ‘/nix/store/0ypaa4x9x0lsyygciasw9m1v4jswgm49-avr-gcc-libc.drv’ failed
What might the problem be? What can I do to get avr-gcc-libc to install successfully?

Undefined reference (but nm says the function exists) [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I have a library from a camera manufacturer, and in the demo code provided, a function called metadata_init() works fine, in my code though, I get an undefined reference error.
The make output from the demo code:
/opt/linaro-multilib-2013.09-gcc4.8/bin/arm-linux-gnueabihf-gcc -lm -g -L"/home/aro/Downloads" -o hicore demoS2.c -lpthread -lyuvlib -lrt
and thats it, the build succeeds fine, I will have a working ./hicore application in there.
My project is a little bit more complicated, and I compile using eclipse.
The console output is:
11:33:23 **** Build of configuration Camera-R4-Debug for project Camera ****
make all
Building file: ../src/Camera.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Camera.d" -MT"src/Camera.o" -o "src/Camera.o" "../src/Camera.cpp"
../src/Camera.cpp: In function ‘int metadata_construct_http_message(char*, METADATA_HTTP_MESSAGE_TYPE, void*, int*)’:
../src/Camera.cpp:379:24: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
"</svg>\r\n";
^
../src/Camera.cpp: In function ‘int main()’:
../src/Camera.cpp:426:97: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
(void)metadata_init("stream.cgi", strlen("stream.cgi"), metadata_construct_http_message);
^
Finished building: ../src/Camera.cpp
Building file: ../src/CameraFrameGrabber.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraFrameGrabber.d" -MT"src/CameraFrameGrabber.o" -o "src/CameraFrameGrabber.o" "../src/CameraFrameGrabber.cpp"
Finished building: ../src/CameraFrameGrabber.cpp
Building file: ../src/CameraLogger.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/home/aro/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraLogger.d" -MT"src/CameraLogger.o" -o "src/CameraLogger.o" "../src/CameraLogger.cpp"
Finished building: ../src/CameraLogger.cpp
Building file: ../src/CameraParameter.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/opt/Camerasdk/R4/include -I"/home/aro/cameraBuilds/Wrapper/include" -I"/opt/ExternalLibraries/curl/Camera/R4/include" -I"/opt/ExternalLibraries/libxml2/Camera/R4/include" -I"/opt/ExternalLibraries/OpenCV24/Camera/R4/include" -I"/home/aro/cameraBuilds/Camera" -I/opt/InternalLibraries/include -I/opt/InternalLibraries/include_linux -I/opt/InternalLibraries/ipslib/include -I/opt/InternalLibraries/ipsstream/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/CameraParameter.d" -MT"src/CameraParameter.o" -o "src/CameraParameter.o" "../src/CameraParameter.cpp"
Finished building: ../src/CameraParameter.cpp
Building target: Camera
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/opt/Camerasdk/R4/lib -L"/cameraBuilds/Wrapper/Camera-R4-Debug" -L"/opt/ExternalLibraries/curl/Camera/R4/lib" -L"/opt/ExternalLibraries/libxml2/Camera/R4/lib" -L"/opt/ExternalLibraries/OpenCV24/Camera/R4/lib" -L"/opt/DetectionModules/Camera/R4/lib" -L/home/aro/Downloads -o "Camera" ./src/Camera.o ./src/CameraFrameGrabber.o ./src/CameraLogger.o ./src/CameraParameter.o -lWrapper -lxml2 -lopencv_highgui -lopencv_imgproc -lopencv_core -lpthread -lyuvlib -lrt -llibjasper -llibjpeg -llibpng -llibtiff -lzlib -lcurl
./src/Camera.o: In function `main':
/home/aro/cameraBuilds/Camera/Camera-R4-Debug/../src/Camera.cpp:426: undefined reference to `metadata_init(char*, int, int (*)(char*, METADATA_HTTP_MESSAGE_TYPE, void*, int*))'
collect2: error: ld returned 1 exit status
make: *** [Camera] Error 1
11:33:24 Build Finished (took 1s.212ms)
The code itself is the very same thing, I just copied it over.
Metadata.h:
#ifndef _HIK_METADATA_H_
#define _HIK_METADATA_H_
const int max_http_body_len = 100 * 1024;
typedef enum
{
CMD_ADD_TYPE = 1,
CMD_OTHER,
} METADATA_CTRL_TYPE;
typedef struct
{
int length;
int fd;
METADATA_CTRL_TYPE cmd_type;
} METADATA_HEADER;
typedef struct
{
char option[128];
int share_socket;
} METADATA_ADD_CFG;
typedef enum
{
HTTP_HEADER_TYPE = 1,
HTTP_BODY_TYPE,
} METADATA_HTTP_MESSAGE_TYPE;
typedef struct
{
char boundary[64];
char http_content_type[64];
char multipart_content_type[64];
} METADATA_MULTIPART_TYPE;
typedef int (*p_metadata_construct_http_msg_callback_f)(char *p_option, METADATA_HTTP_MESSAGE_TYPE cmd_type, void *p_data, int *p_data_len);
int metadata_init(char *p_metadata_url, int url_len, p_metadata_construct_http_msg_callback_f p_callback_f);
#endif
In Camera.cpp:
#include "Metadata.h"
int metadata_construct_http_message(char *p_option, METADATA_HTTP_MESSAGE_TYPE cmd_type, void *p_data, int *p_data_len)
{
// Removed for SO
return 0;
}
int main()
{
(void)metadata_init("stream.cgi", strlen("stream.cgi"), metadata_construct_http_message);
...
}
What causes this, and how can I debug this issue to narrow down how to fix it?
It think the problem could be that metadata_init is a C function, but you use it from a C++ code.
In case of this, extern "C" must be used in the header file, like this:
#ifdef __cplusplus
extern "C" {
#endif
// embed the whole contents of the header file here, I just put the function here for brevity
int metadata_init(char *p_metadata_url, int url_len, p_metadata_construct_http_msg_callback_f p_callback_f);
#ifdef __cplusplus
}
#endif
It is because of name mangling rules. Names are mangled differently in C and C++. With extern "C", you tell the compiler that the names inside should be used with "C" mangling.
C++ has to do a complex name mangling compared to C, because it has to embed almost all signature information to a name (all parameters type), while in C, the mangled name usually is the same as the function name, or there is a _ prepended.

Undefined reference with Eclipse for source in different directory

I have an old source which I need to integrate in my project in Eclipse (in Ubuntu 12.04).
The old source code works perfectly on its own. But the only problem with it is - I have just one .cpp file (which contains the main) and all others are .h files which contains the definitions and declarations. I fixed this by creating a source file for each header file and copying the function definitions in these files and left the declarations in the header files.
I added these files using eclipse so those files actually are getting compiled.
Note that, I have added this source code into "src/segment". Here is my directory listing. These files also show up in the eclipse project. My main function is in "HelloOpenCV2.cpp"
[eeuser#roadrunner src]$ ls
CameraPoseFromFundamentalMatrix.d InterestPoints.o
CameraPoseFromFundamentalMatrix.o LinesAndComponents.d
GLViz.d LinesAndComponents.o
GLViz.o MorphologicalManip.d
GraphImageSegmentation.d MorphologicalManip.o
GraphImageSegmentation.o MultiviewColorConsistency.d
HelloOpenCV2.d MultiviewColorConsistency.o
HelloOpenCV2.o segment
HomographyWarp.d StereoCamDepth.d
HomographyWarp.o StereoCamDepth.o
ImageManipulations.d subdir.mk
ImageManipulations.o VideoProc.d
InterestPoints.d VideoProc.o
[eeuser#roadrunner src]$ ls segment/
convolve.d filter.d imconv.d segment-graph.d subdir.mk
convolve.o filter.o imconv.o segment-graph.o
disjoint-set.d image.d imutil.d segment-image.d
disjoint-set.o image.o imutil.o segment-image.o
Here is my compilation log as generated by eclipse.
18:54:21 **** Build of configuration Debug for project HelloOpenCV2 ****
make all
Building file: ../src/segment/convolve.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/convolve.d" -MT"src/segment/convolve.d" -o "src/segment/convolve.o" "../src/segment/convolve.cpp"
Finished building: ../src/segment/convolve.cpp
Building file: ../src/segment/disjoint-set.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/disjoint-set.d" -MT"src/segment/disjoint-set.d" -o "src/segment/disjoint-set.o" "../src/segment/disjoint-set.cpp"
Finished building: ../src/segment/disjoint-set.cpp
Building file: ../src/segment/filter.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/filter.d" -MT"src/segment/filter.d" -o "src/segment/filter.o" "../src/segment/filter.cpp"
Finished building: ../src/segment/filter.cpp
Building file: ../src/segment/image.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/image.d" -MT"src/segment/image.d" -o "src/segment/image.o" "../src/segment/image.cpp"
Finished building: ../src/segment/image.cpp
Building file: ../src/segment/imconv.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/imconv.d" -MT"src/segment/imconv.d" -o "src/segment/imconv.o" "../src/segment/imconv.cpp"
Finished building: ../src/segment/imconv.cpp
Building file: ../src/segment/imutil.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/imutil.d" -MT"src/segment/imutil.d" -o "src/segment/imutil.o" "../src/segment/imutil.cpp"
Finished building: ../src/segment/imutil.cpp
Building file: ../src/segment/segment-graph.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/segment-graph.d" -MT"src/segment/segment-graph.d" -o "src/segment/segment-graph.o" "../src/segment/segment-graph.cpp"
Finished building: ../src/segment/segment-graph.cpp
Building file: ../src/segment/segment-image.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/segment/segment-image.d" -MT"src/segment/segment-image.d" -o "src/segment/segment-image.o" "../src/segment/segment-image.cpp"
Finished building: ../src/segment/segment-image.cpp
Building file: ../src/CameraPoseFromFundamentalMatrix.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/CameraPoseFromFundamentalMatrix.d" -MT"src/CameraPoseFromFundamentalMatrix.d" -o "src/CameraPoseFromFundamentalMatrix.o" "../src/CameraPoseFromFundamentalMatrix.cpp"
Finished building: ../src/CameraPoseFromFundamentalMatrix.cpp
Building file: ../src/GLViz.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/GLViz.d" -MT"src/GLViz.d" -o "src/GLViz.o" "../src/GLViz.cpp"
Finished building: ../src/GLViz.cpp
Building file: ../src/GraphImageSegmentation.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/GraphImageSegmentation.d" -MT"src/GraphImageSegmentation.d" -o "src/GraphImageSegmentation.o" "../src/GraphImageSegmentation.cpp"
Finished building: ../src/GraphImageSegmentation.cpp
Building file: ../src/HelloOpenCV2.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/HelloOpenCV2.d" -MT"src/HelloOpenCV2.d" -o "src/HelloOpenCV2.o" "../src/HelloOpenCV2.cpp"
Finished building: ../src/HelloOpenCV2.cpp
Building file: ../src/HomographyWarp.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/HomographyWarp.d" -MT"src/HomographyWarp.d" -o "src/HomographyWarp.o" "../src/HomographyWarp.cpp"
Finished building: ../src/HomographyWarp.cpp
Building file: ../src/ImageManipulations.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/ImageManipulations.d" -MT"src/ImageManipulations.d" -o "src/ImageManipulations.o" "../src/ImageManipulations.cpp"
Finished building: ../src/ImageManipulations.cpp
Building file: ../src/InterestPoints.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/InterestPoints.d" -MT"src/InterestPoints.d" -o "src/InterestPoints.o" "../src/InterestPoints.cpp"
Finished building: ../src/InterestPoints.cpp
Building file: ../src/LinesAndComponents.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/LinesAndComponents.d" -MT"src/LinesAndComponents.d" -o "src/LinesAndComponents.o" "../src/LinesAndComponents.cpp"
Finished building: ../src/LinesAndComponents.cpp
Building file: ../src/MorphologicalManip.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/MorphologicalManip.d" -MT"src/MorphologicalManip.d" -o "src/MorphologicalManip.o" "../src/MorphologicalManip.cpp"
Finished building: ../src/MorphologicalManip.cpp
Building file: ../src/MultiviewColorConsistency.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/MultiviewColorConsistency.d" -MT"src/MultiviewColorConsistency.d" -o "src/MultiviewColorConsistency.o" "../src/MultiviewColorConsistency.cpp"
Finished building: ../src/MultiviewColorConsistency.cpp
Building file: ../src/StereoCamDepth.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/StereoCamDepth.d" -MT"src/StereoCamDepth.d" -o "src/StereoCamDepth.o" "../src/StereoCamDepth.cpp"
Finished building: ../src/StereoCamDepth.cpp
Building file: ../src/VideoProc.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/local/include -O0 -g3 -w -c -fmessage-length=0 -MMD -MP -MF"src/VideoProc.d" -MT"src/VideoProc.d" -o "src/VideoProc.o" "../src/VideoProc.cpp"
Finished building: ../src/VideoProc.cpp
Building target: HelloOpenCV2
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "HelloOpenCV2" ./src/segment/convolve.o ./src/segment/disjoint-set.o ./src/segment/filter.o ./src/segment/image.o ./src/segment/imconv.o ./src/segment/imutil.o ./src/segment/segment-graph.o ./src/segment/segment-image.o ./src/CameraPoseFromFundamentalMatrix.o ./src/GLViz.o ./src/GraphImageSegmentation.o ./src/HelloOpenCV2.o ./src/HomographyWarp.o ./src/ImageManipulations.o ./src/InterestPoints.o ./src/LinesAndComponents.o ./src/MorphologicalManip.o ./src/MultiviewColorConsistency.o ./src/StereoCamDepth.o ./src/VideoProc.o -lopencv_core -lGL -lGLU -lglut -lopencv_stitching -lopencv_contrib -lopencv_nonfree -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_flann -lopencv_imgproc -lopencv_highgui
../src/segment/filter.cpp:39: error: undefined reference to 'image<float>::image(int, int, bool)'
../src/segment/filter.cpp:40: error: undefined reference to 'image<float>::image(int, int, bool)'
../src/segment/filter.cpp:41: error: undefined reference to 'convolve_even(image<float>*, image<float>*, std::vector<float, std::allocator<float> >&)'
../src/segment/filter.cpp:42: error: undefined reference to 'convolve_even(image<float>*, image<float>*, std::vector<float, std::allocator<float> >&)'
../src/segment/filter.cpp:44: error: undefined reference to 'image<float>::~image()'
../src/segment/filter.cpp:52: error: undefined reference to 'imageUCHARtoFLOAT(image<unsigned char>*)'
../src/segment/filter.cpp:54: error: undefined reference to 'image<float>::~image()'
../src/segment/filter.cpp:63: error: undefined reference to 'image<float>::image(int, int, bool)'
../src/segment/imconv.cpp:15: error: undefined reference to 'image<unsigned char>::image(int, int, bool)'
../src/segment/imconv.cpp:31: error: undefined reference to 'image<rgb>::image(int, int, bool)'
../src/segment/imconv.cpp:46: error: undefined reference to 'image<float>::image(int, int, bool)'
../src/segment/imconv.cpp:73: error: undefined reference to 'image<unsigned char>::image(int, int, bool)'
../src/segment/imconv.cpp:90: error: undefined reference to 'void min_max<float>(image<float>*, float*, float*)'
../src/segment/imconv.cpp:97: error: undefined reference to 'image<long>::image(int, int, bool)'
../src/segment/imconv.cpp:110: error: undefined reference to 'image<unsigned char>::image(int, int, bool)'
../src/segment/imconv.cpp:127: error: undefined reference to 'void min_max<long>(image<long>*, long*, long*)'
../src/segment/imconv.cpp:135: error: undefined reference to 'image<unsigned char>::image(int, int, bool)'
../src/segment/imconv.cpp:152: error: undefined reference to 'void min_max<short>(image<short>*, short*, short*)'
../src/segment/segment-image.cpp:62: error: undefined reference to 'smooth(image<float>*, float)'
../src/segment/segment-image.cpp:63: error: undefined reference to 'smooth(image<float>*, float)'
../src/segment/segment-image.cpp:64: error: undefined reference to 'smooth(image<float>*, float)'
../src/segment/segment-image.cpp:65: error: undefined reference to 'image<float>::~image()'
../src/segment/segment-image.cpp:66: error: undefined reference to 'image<float>::~image()'
../src/segment/segment-image.cpp:120: error: undefined reference to 'image<rgb>::image(int, int, bool)'
../src/segment/segment-image.cpp:121: error: undefined reference to 'image<int>::image(int, int, bool)'
../src/segment/pnmfile.h:166: error: undefined reference to 'image<rgb>::image(int, int, bool)'
../src/segment/pnmfile.h:166: error: undefined reference to 'image<rgb>::image(int, int, bool)'
collect2: ld returned 1 exit status
make: *** [HelloOpenCV2] Error 1
18:54:30 Build Finished (took 8s.826ms)
I can also confirm that .o (object) files for each of the source files are generated. However, I do not understand how to fix the undefined reference error.
Would like to add that the file image.cpp / image.h contain a class definition. I have not added these 2 files as add->class have added them as add->source and add->header
Just applied "nm" command on image.o. Got an empty response. Although image.o is a 24 byte file.
image.h contains the template class declaration and image.cpp contains class function definition.
Image is a template class. The header and source for it are as -
/*
* image.h
*
* Created on: 25 Oct, 2014
* Author: eeuser
*/
#ifndef IMAGE_H_
#define IMAGE_H_
#include <cstring>
/* use imRef to access image data. */
#define imRef(im, x, y) (im->access[y][x])
/* use imPtr to get pointer to image data. */
#define imPtr(im, x, y) &(im->access[y][x])
template <class T>
class image {
public:
/* create an image */
image(int width, int height, bool init = true);
/* delete an image */
~image();
/* init an image */
void init(const T &val);
/* copy an image */
image<T> *copy() const;
/* get the width of an image. */
int width() const { return w; }
/* get the height of an image. */
int height() const { return h; }
/* image data. */
T *data;
/* row pointers. */
T **access;
private:
int w, h;
};
#endif /* IMAGE_H_ */
The source:
/*
* image.cpp
*
* Created on: 25 Oct, 2014
* Author: eeuser
*/
#include "image.h"
template <class T>
image<T>::image(int width, int height, bool init) {
w = width;
h = height;
data = new T[w * h]; // allocate space for image data
access = new T*[h]; // allocate space for row pointers
// initialize row pointers
for (int i = 0; i < h; i++)
access[i] = data + (i * w);
if (init)
memset(data, 0, w * h * sizeof(T));
}
template <class T>
image<T>::~image() {
delete [] data;
delete [] access;
}
template <class T>
void image<T>::init(const T &val) {
T *ptr = imPtr(this, 0, 0);
T *end = imPtr(this, w-1, h-1);
while (ptr <= end)
*ptr++ = val;
}
template <class T>
image<T> *image<T>::copy() const {
image<T> *im = new image<T>(w, h, false);
memcpy(im->data, data, w * h * sizeof(T));
return im;
}
I turned on the extra warning flags in g++ (-Wextra). It complained about a bunch of static functions I had. I just changed those to normal functions. I guess this is ok, since those functions were not associated with a class.

Getting Undefined Reference to Perl on C++

Well, first of all, sorry about my bad english!
I'm new to linux, g++ and perl, and I'm getting some problems here.
I have a code in G++ which calls a perl .pl file to return a information. Right now, I'm just returning 1 or 0 from the perl .pl file for tests and to understand how does it works. But the problem is that I'm getting this from the $make:
sathlervbn Spam C # make clean;make
rm -f *.o
g++ -Wall -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.14/CORE -c -o filedir.o filedir.cpp
g++ -Wall -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.14/CORE -c -o main.o main.cpp
main.cpp: In function ‘int main(int, char**, char**)’:
main.cpp:112:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
main.cpp:112:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
g++ -L/usr/lib -Wall -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.14/CORE - lperl -ldl -lm -lpthread -lc -lcrypt -o main filedir.o main.o
main.o: In function `getInfoPerl(std::string)':
main.cpp:(.text+0x1a): undefined reference to `Perl_push_scope'
main.cpp:(.text+0x33): undefined reference to `Perl_save_int'
main.cpp:(.text+0x73): undefined reference to `Perl_markstack_grow'
main.cpp:(.text+0xcd): undefined reference to `Perl_stack_grow'
main.cpp:(.text+0xfa): undefined reference to `Perl_newSVpv'
main.cpp:(.text+0x10d): undefined reference to `Perl_sv_2mortal'
main.cpp:(.text+0x13b): undefined reference to `Perl_call_pv'
main.cpp:(.text+0x18f): undefined reference to `Perl_sv_2iv_flags'
main.cpp:(.text+0x1bd): undefined reference to `Perl_free_tmps'
main.cpp:(.text+0x1ca): undefined reference to `Perl_pop_scope'
main.o: In function `main':
main.cpp:(.text+0x206): undefined reference to `Perl_sys_init3'
main.cpp:(.text+0x20b): undefined reference to `perl_alloc'
main.cpp:(.text+0x21d): undefined reference to `perl_construct'
main.cpp:(.text+0x265): undefined reference to `perl_parse'
main.cpp:(.text+0x272): undefined reference to `perl_run'
main.cpp:(.text+0x2fd): undefined reference to `perl_destruct'
main.cpp:(.text+0x30a): undefined reference to `perl_free'
main.cpp:(.text+0x30f): undefined reference to `Perl_sys_term'
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
The main.cpp code is:
#include <EXTERN.h>
#include <perl.h>
#include <iostream>
#include <cstdio>
#include "filedir.h"
using namespace std;
PerlInterpreter *my_perl;
int getInfoPerl(string email){
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(email.c_str(),0)));
PUTBACK;
call_pv("spamTeste", G_SCALAR);
SPAGAIN;
int resultado = POPi;
PUTBACK;
FREETMPS;
LEAVE;
return resultado;
}
int main(int argc, char **argv, char **env) {
char *my_argv[] = { " ", "spamPerl.pl" };
PERL_SYS_INIT3 (&argc, &argv, &env);
my_perl = perl_alloc();
perl_construct ( my_perl );
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
perl_run(my_perl);
cout << "Resultado " << getInfoPerl("email/email.txt") << endl;
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
foobar bla bla bla another part from the code: doesn't matter.
}
Here is the makefile:
#CC= /usr/bin/g++
CPP = g++
CPPFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ccopts)
#LD= /usr/bin/g++
LD = g++
LFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ldopts)
#LFLAGS = -Wall -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lc -lcrypt
MAINOBJS = filedir.o main.o
EMAILS = main
EXECS = $(EMAILS)
#Regra Implicita:
.c.o:
$(CPP) $(CPPFLAGS) -c $<
all: emails
emails: $(EMAILS)
main: $(MAINOBJS)
$(LD) -L/usr/lib $(LFLAGS) -o $# $(MAINOBJS)
clean:
rm -f *.o
What I did? I've tried installing libperl-dev package, update the perl, and nothing solved.
I really need to fix this! Can someone help me?
UPDATE:
Changed the Header from main.cpp to:
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#ifdef __cplusplus
}
#endif
#include <iostream>
#include <cstdio>
#include "filedir.h"
Didn't work...
The answer previous is right, it is cause by the sequence of gcc parameters. I test a sample code provided by the official perlembed tutorial:
http://perldoc.perl.org/perlembed.html
if the compile option is
cc -o interp interp.c perl -MExtUtils::Embed -e ccopts -e ldopts
as provided by the tutorial, it is right.
But any other sequence is wrong, for example:
cc interp.c -o interp perl -MExtUtils::Embed -e ccopts -e ldopts
cc perl -MExtUtils::Embed -e ccopts -e ldopts interp.c -o interp
so make sure in your Makefile -o goes the first and source file goes the second.
The problem was in the makefile:
#CC= /usr/bin/g++
CPP = g++
CPPFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ccopts)
#LD= /usr/bin/g++
LD = g++
LFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ldopts)
#LFLAGS = -Wall -Wl,-E -fstack-protector -L/usr/local/lib -L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lc -lcrypt
MAINOBJS = filedir.o main.o
EMAILS = main
EXECS = $(EMAILS)
#Regra Implicita:
.c.o:
$(CPP) $(CPPFLAGS) -c $<
all: emails
emails: $(EMAILS)
main: $(MAINOBJS)
$(LD) -L/usr/lib $(LFLAGS) -o $# $(MAINOBJS)
clean:
rm -f *.o
As you can see, in this line, the code:
main: $(MAINOBJS)
$(LD) -L/usr/lib $(LFLAGS) -o $# $(MAINOBJS)
Should have the $(LFLAGS) after the $(MAINOBJS), so it should be:
main: $(MAINOBJS)
$(LD) -L/usr/lib -o $# $(MAINOBJS) $(LFLAGS)
Now, the linker is working perfectly. I'm sorry, but I can't say exactly why this is necessary, I've just discovered.

Compilation Error with make file

I've developed a C++ project using eclipse. When I launch the Run command from within the IDE everything will work fine and programs exits with success.
This is the build output obtained with Eclipse's make file:
**** Build of configuration Debug for project IVPM ****
make all
Building file: ../IVPM.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"IVPM.d" -MT"IVPM.d" -o "IVPM.o" "../IVPM.cpp"
Finished building: ../IVPM.cpp
Building file: ../TemplateMatx3.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"TemplateMatx3.d" -MT"TemplateMatx3.d" -o "TemplateMatx3.o" "../TemplateMatx3.cpp"
Finished building: ../TemplateMatx3.cpp
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: IVPM
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "IVPM" ./IVPM.o ./Matx3.o ./TemplateMatx3.o ./main.o -lopencv_core -lpng -lopencv_highgui
Finished building target: IVPM
**** Build Finished ****
I was now trying to write a makefile on my own but am not able to compile with success. Here is what I've done so far:
all:main
main:IVPM.o TemplateMatx3.o
g++ IVPM.o TemplateMatx3.o -L/usr/local/lib -lopencv_core -lpng -lopencv_highgui -o main -c main.cpp
TemplateMatx3.o:TemplateMatx3.cpp
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c TemplateMatx3.cpp
IVPM.o:IVPM.cpp
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c IVPM.cpp
clean:
rm -rf *o main
But compiling on a shell with the make command will result in the following errors:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c IVPM.cpp
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c TemplateMatx3.cpp
g++ IVPM.o TemplateMatx3.o -L/usr/local/lib -lopencv_core -lpng -lopencv_highgui -o main -c main.cpp
In file included from /usr/include/c++/4.5/type_traits:35:0,
from IVPM.h:39,
from main.cpp:8:
/usr/include/c++/4.5/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
In file included from main.cpp:9:0:
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadImagesFromFileAndProcessAndSave(const std::string&, const std::string&, const std::string&, IVPM<Matx3DataType>::loadImageType, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:140:39: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘std::vector<TemplateMatx3<Matx3DataType>*>* IVPM<Matx3DataType>::loadImagesFromFileAndProcessAndReturn(const std::string&, const std::string&, IVPM<Matx3DataType>::loadImageType, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:208:39: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::convertMatx3VectorAndProcessAndSave(std::vector<TemplateMatx3<Matx3DataType>*>*, const std::string&, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:555:58: error: there are no arguments to ‘to_string’ that depend on a template parameter, so a declaration of ‘to_string’ must be available
IVPM.cpp:555:58: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadMatx3FromFileAndProcessAndSave(const std::string&, const std::string&, IVPM<Matx3DataType>::matx3FileType, const std::string&, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:704:38: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘std::vector<TemplateMatx3<Matx3DataType>*>* IVPM<Matx3DataType>::loadMatx3FromFileAndProcessAndReturn(const std::string&, const std::string&, IVPM<Matx3DataType>::matx3FileType, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:740:38: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadVideoAndProcessAndSave(const std::string&, const std::string&, IVPM<Matx3DataType>::saveImageFormat, float, float, float, bool, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType) [with Matx3DataType = double, std::string = std::basic_string<char>]’:
main.cpp:84:2: instantiated from here
IVPM.cpp:315:118: error: ‘to_string’ was not declared in this scope
make: *** [main] Error 1
Apparently the compiler is not able to find matching functions of the std library. But I've included the std library in my compiling options, so why is the compiler complaining? And what is the correct procedure to follow?