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?
Related
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.
I've been attempting to build wxWidgets 3.1.0 in Cygwin. I followed the process described in the install.txt, summarized below:
cd $WXWIN
mkdir build-debug
cd build-debug
../configure --enable-debug
make -j4
I have also tried a couple other flags for configure such as --with-X11, as suggest by this guide. The error I keep receiving, however, is the following:
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_strvararg.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/strvararg.cpp
In file included from ../src/common/string.cpp:39:0:
../include/wx/xlocale.h: In function ‘double wxStrtod_lA(const char*, char**, const wxXLocale&)’:
../include/wx/xlocale.h:243:54: error: ‘strtod_l’ was not declared in this scope
{ return wxCRT_Strtod_lA(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:245:60: error: ‘strtol_l’ was not declared in this scope
{ return wxCRT_Strtol_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_lA(const char*, char**, int, const wxXLocale&)’:
../include/wx/xlocale.h:247:61: error: ‘strtoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lA(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘double wxStrtod_l(const wchar_t*, wchar_t**, const wxXLocale&)’:
../include/wx/xlocale.h:301:58: error: ‘wcstod_l’ was not declared in this scope
{ return wxCRT_Strtod_lW(c, endptr, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long int wxStrtol_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:303:64: error: ‘wcstol_l’ was not declared in this scope
{ return wxCRT_Strtol_lW(c, endptr, base, loc.Get()); }
^
../include/wx/xlocale.h: In function ‘long unsigned int wxStrtoul_l(const wchar_t*, wchar_t**, int, const wxXLocale&)’:
../include/wx/xlocale.h:305:65: error: ‘wcstoul_l’ was not declared in this scope
{ return wxCRT_Strtoul_lW(c, endptr, base, loc.Get()); }
^
/home/acohen8/wxWidgets-3.1.0/build-debug/bk-deps g++ -c -o basedll_sysopt.o -D__WXMSW__ -DWXBUILDING -I../src/regex -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE_BASE=1 -Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy -Woverloaded-virtual -D_FILE_OFFSET_BITS=64 -I/home/acohen8/wxWidgets-3.1.0/build-debug/lib/wx/include/msw-unicode-3.1 -I../include -g -O0 ../src/common/sysopt.cpp
make: *** [Makefile:25366: basedll_string.o] Error 1
make: *** Waiting for unfinished jobs....
I would very much appreciate some suggestions on this!
This is most likely already fixed in wx's git master by this commit. But you can work around the problem by using configure --disable-xlocale.
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?
while executing ./Allwmake getting the ambiguous error. error is given below.
Found nvcc -- enabling CUDA support.
SOURCE=lduMatrixConversion/lduMatrixConversion.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/home/suraj/ispm-sparse-lib-master -isystem /usr/local/cuda-7.5/include -IlnInclude -I. -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64Gcc48DPOpt/lduMatrixConversion.o
SOURCE=GPUPCG/GPUPCG.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/home/suraj/ispm-sparse-lib-master -isystem /usr/local/cuda-7.5/include -IlnInclude -I. -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64Gcc48DPOpt/GPUPCG.o
SOURCE=AsyncPrecondProvider/AsyncPrecondProvider.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/home/suraj/ispm-sparse-lib-master -isystem /usr/local/cuda-7.5/include -IlnInclude -I. -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64Gcc48DPOpt/AsyncPrecondProvider.o
SOURCE=GPUSolverData/GPUSolverData.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -I/home/suraj/ispm-sparse-lib-master -isystem /usr/local/cuda-7.5/include -IlnInclude -I. -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude -I/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64Gcc48DPOpt/GPUSolverData.o
In file included from /home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.H:281,
from lnInclude/solverPersistentData.H:43,
from GPUPCG/GPUPCG.H:43,
from GPUPCG/GPUPCG.C:32:
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.C: In static member function ‘static const Type& Foam::MeshObject<Mesh, MeshObjectType, Type>::New(const Mesh&) [with Mesh = Foam::lduMesh, MeshObjectType = Foam::UpdateableMeshObject, Type = Foam::solverPersistentData<Foam::lduMesh, Foam::GPUSolverData>]’:
GPUPCG/GPUPCG.C:65: instantiated from here
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.C:48: error: reference to ‘Foam::solverPersistentData<Foam::lduMesh, Foam::GPUSolverData>::typeName’ is ambiguous
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/IOobject.H:177: error: candidates are: const Foam::word Foam::IOobject::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/regIOobject.H:125: error: const Foam::word Foam::regIOobject::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.H:168: error: const Foam::word Foam::meshObject::typeName
lnInclude/solverPersistentData.H:66: error: const Foam::word Foam::solverPersistentDataName::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.C:59: error: reference to ‘Foam::solverPersistentData<Foam::lduMesh, Foam::GPUSolverData>::typeName’ is ambiguous
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/IOobject.H:177: error: candidates are: const Foam::word Foam::IOobject::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/regIOobject.H:125: error: const Foam::word Foam::regIOobject::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.H:168: error: const Foam::word Foam::meshObject::typeName
lnInclude/solverPersistentData.H:66: error: const Foam::word Foam::solverPersistentDataName::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/MeshObject.C:65: error: reference to ‘Foam::solverPersistentData<Foam::lduMesh, Foam::GPUSolverData>::typeName’ is ambiguous
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/IOobject.H:177: error: candidates are: const Foam::word Foam::IOobject::typeName
/home/suraj/OpenFOAM/OpenFOAM-2.4.x/src/OpenFOAM/lnInclude/regIOobject.H:125: error: const Foam::word Foam::regIOobject::typeName
and most of the errors are due to ambiguity in the code.
the files are used from OpenFOAM2.4.x distriution. which are available online.
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.