My cpp program worked fine in terminal and gave output also.It was run using:
g++ cipher.cpp -lmysqlcppconn
But when i tried the same in eclipse it is showing the below error?
12:07:07 **** Incremental Build of configuration Debug for project cipher ****
make all
Building file: ../src/cipher.cpp
Invoking: GCC C++ Compiler
g++ -I../usr/include/cppconn -I../usr/include -I/usr/include /boost -O0 -g3 -Wall -c -fmessage-length=0 -lmysqlcppconn -lmysqlclient -MMD -MP -MF"src/cipher.d" -MT"src/cipher.d" -o "src/cipher.o" "../src/cipher.cpp"
/root/Downloads/cipher/Debug/../src/cipher.cpp:528: undefined reference to `sql::mysql::get_driver_instance()'
collect2: ld returned 1 exit status
make: *** [cipher] Error 1
11:54:39 Build Finished (took 472ms)
The program header portion includes
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include "mysql_driver.h"
#include "mysql_connection.h"
using namespace sql::mysql;
The options -lmysqlcppconn and -lmysqlclient are included in project->properties->c/c++Build->Settings->miscalleneous->other flags
Eclipse IDE Version: Luna Service Release 2 (4.4.2)
what all "includes" and "libraries" are to be specified in eclipse "path and symbols"?
I have gone through answers of similar queries but they didnt helped me.
I am working on centos6.6
Related
I installed casacore from source using the GitHub repository on my Ubuntu 18.04. The installation completes without any errors and the respective files are written to the expected directories (the .h files to /usr/local/include & libraries to /usr/local/lib). On trying to compile a basic C++ file using these I'm given the following error:
tmp/ccBxZcf3.o: In function 'main': /home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::MeasurementSet()'
/home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::~MeasurementSet()'
collect2: error: ld returned 1 exit status
The compiler command that I use is as follows:
g++ -g -Wall -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms ms.cpp -o ms
The ms.cpp file being compiled is extremely simple and just creates an empty measurement set to test for successful linking and is as follows:
//ms.cpp
#include <iostream>
#include </usr/local/include/casacore/ms/MeasurementSets/MeasurementSet.h>
int main(){
casacore::MeasurementSet ms = casacore::MeasurementSet();
return 0;
}
Here is all that I have tried:
a) Building from source using GitHub instructions,
b) Installing from Ubuntu repository.
Thanks in advance for your time!
When compiling manually with g++ you need to first specify your sources, and then the dependencies (libraries):
g++ -o ms ms.cpp -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms -g -Wall
Better just use CMake if you plan to have something more that just one cpp.
Related topics:
linking files in g++
gcc-g++-parameter-order
Alternatively, you can use the -Wl,--no-as-needed options:
g++ -g -Wall -I/usr/local/include -L/usr/local/lib -Wl,--no-as-needed -lcasa_ms ms.cpp -o ms
I am trying to include a library from Github (https://github.com/dcjones/hat-trie).
The installation worked fine and I was able to add the library
to the linker in Eclipse
but the problem is that I don't know how to use it.
I have added it as a header
#include <hat-trie.h>
but it's giving this error:
18:49:31 **** Incremental Build of configuration Debug for project test2 ****
make all
Building file: ../src/test2.cpp
Invoking: GCC C++ Compiler
g++ -std=c++1y -std=c++11 -I/home/use1/boost_1_58_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test2.d" -MT"src/test2.d" -o "src/test2.o" "../src/test2.cpp"
**../src/test2.cpp:28:22: fatal error: hat-trie.h: No such file or directory
#include <hat-trie.h>**
^
compilation terminated.
make: *** [src/test2.o] Error 1
18:49:33 Build Finished (took 2s.831ms)
Any idea how can I fix this?
#include <iostream>
#include <Magick++.h>
int main()
{
Magick::InitializeMagick(NULL);
Magick::Image im;
im.read("/home/chase/Desktop/m42.jpg");
im.display();
return 0;
}
I get the following error when I try to compile in eclipse...
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -I/usr/include/x86_64-linux-gnu/ImageMagick-6 -I/usr/include/ImageMagick-6 -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Stacking
Invoking: GCC C++ Linker
g++ -L../ -o "Stacking" ./main.o -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16 -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16
./main.o: In function `main':
/home/chase/workspace/Stacking/Debug/../main.cpp:8: undefined reference to `Magick::Image::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
makefile:44: recipe for target 'Stacking' failed
make: *** [Stacking] Error 1
Why does the read function not compile. I used the package config tool in eclipse to set up Magick++. Also as far as I can tell all the other functions work fine. I am using Ubuntu. I installed Magic++ using sudo apt-get install libmagick++-dev.
Update:
I got it to work. I had upgraded to g++-5. When I compiled with g++-4.9 it worked. Wonder why it does not work with g++-5?
Why does the read function not compile
Your read function does compile. What you have is a link problem.
why it does not work with g++-5
Because g++-4.x and g++-5.x use different ABI, and are not link-compatible (and your libMagick* libraries were built with g++-4.x).
So I have been trying to install DDD. I am on a Mac OS X 10.9(Mavericks) and I have the latest Xcode installed. Whenever I run my configure file the last thing I get is the following:
checking whether c++ accepts -g... yes
checking whether the C++ compiler (c++) compiles a simple program... no
configure: error: You must set the environment variable CXX to a working
C++ compiler. Also check the CXXFLAGS settings.
See the file 'config.log' for further diagnostics.
and whenever I check the config.log file I get:
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
configure:2678:10: fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
configure: failed program was:
#line 2677 "configure"
#include "confdefs.h"
#include <iostream.h>
int main() {
cout << "hello, world!";
; return 0; }
I have downloaded the gcc from sourcefourge and installed gcc-4.9 again, but I still getting the same error. Anybody knows how to fix this or what the problem maybe?
It seems like you are compiling c++ program but you passing .c file to c++ compiler. You passing conftest.c file to c++ compiler, it has to be confest.cpp.
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
This has to be
configure:2684: c++ -o conftest -g -O2 conftest.cpp 1>&5
And
fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
For above error change your code
to #included <iostream>
instead of #include <iostream.h>
Just open you configure file in DDD directory and add the following
`<iostream>
using namespace std;
`
and that should solve this error
I'm trying to embed python code in C++ (Windows 7 + minGW + Python 2.7.2 + Eclipse Indigo with CDT and PyDev).
So, this is the simple code:
#include <Python.h> //Python.h
#include <iostream> //iostream
using namespace std;
int main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
Py_Finalize();
return 0;
}
And I couldn't understant what am I doing wrong.
I include dirrctories C:\Python27\include and C:\Python27\libs but I can't build my project.
1) When I trying to build my project I got this error:
**** Internal Builder is used for build **** g++
-IC:\Python27\include -IC:\Python27\libs -O0 -g3 -Wall -c
-fmessage-length=0 -o main.o ..\main.cpp g++ -o testpy2.exe main.o
main.o: In function `main':
C:\Users\const\workspace\testpy2\Debug/../main.cpp:7: undefined
reference to `_imp__Py_Initialize'
C:\Users\const\workspace\testpy2\Debug/../main.cpp:9: undefined
reference to `_imp__PyRun_SimpleStringFlags'
C:\Users\const\workspace\testpy2\Debug/../main.cpp:10: undefined
reference to `_imp__Py_Finalize'
collect2: ld returned 1 exit status
Build error occurred, build is stopped Time consumed: 1507 ms.
2) And if I change current toolchain in Eclipse from "minGW" to "CrossGCC" .. I got this error:
**** Build of configuration Release for project testpy ****
make all Building file: ../main.cpp Invoking: Cross G++ Compiler g++
-I"C:\Python27\include" -I"C:\Python27\libs" -O3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o"
"../main.cpp" Finished building: ../main.cpp Building target:
testpy.exe Invoking: Cross G++ Linker g++ -o "testpy.exe" ./main.o
-l"C:/Python27/libs/libpython27.a" -l"C:/Python27/libs/python27.lib"
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe:
cannot find -lC:/Python27/libs/libpython27.a
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe:
cannot find -lC:/Python27/libs/python27.lib collect2: ld returned 1
exit status make: *** [testpy.exe] Error 1
**** Build Finished ****
Could anybody tell me what's wrong with my code or settings or something else?
Thank you
That is a linker error, not a compiler error. You need to link to the python. As you can see, with the "CrossGCC" toolchain you are almost there:
-lC:/Python27/libs/libpython27.a
You need to change this to
-LC:/Python27/libs -lpython