#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).
Related
I am trying to install readline using the command "python setup.py install" by navigating to the directory where i untarred readline 6.2.4.1.
ncurses-6.0 is currently installed in the server.
I have tried recompiling with -fPIC but that also doesnt seem to solve the problem
Command: sudo CFLAGS="-fPIC" python setup.py install
Error Log:
building 'readline' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -fPIC -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/home/roaming/i332346/opt/Python-local/include/python2.7 -c Modules/2.x/readline.c -o build/temp.linux-x86_64-2.7/Modules/2.x/readline.o -Wno-strict-prototypes
In file included from /home/roaming/i332346/opt/Python-local/include/python2.7/Python.h:126:0,
from Modules/2.x/readline.c:8:
/home/roaming/i332346/opt/Python-local/include/python2.7/modsupport.h:27:1: warning: ‘PyArg_ParseTuple’ is an unrecognized format function type [-Wformat=]
PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3);
^
gcc -pthread -shared -fPIC build/temp.linux-x86_64-2.7/Modules/2.x/readline.o readline/libreadline.a readline/libhistory.a -lncurses -o build/lib.linux-x86_64-2.7/readline.so
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: /usr/lib/libncurses.a(lib_termcap.o): relocation R_X86_64_32 against `_nc_globals' can not be used when making a shared object; recompile with -fPIC
/usr/lib/libncurses.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
I tried the following and it worked.
Navigate to ncurses directory that contains configure and run the following
./configure --with-shared --without-debug
make
make install
Then install readline again. The error desappeared. The module was successfully installed.
I am using Netbeans for my C++ project. I compiled my program using make and ran into this error:
collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped
Makefile:4: recipe for target 'barn' failed
make: *** [barn] Error 1
Whereas, when I compiled it in a linux environment(Ubuntu to be precise), it compiled fine. What could have possibly gone wrong?
This is what I got when I typed make -n:
g++ -c main.cc
g++ -c Animal.cc
g++ -c Bird.cc
g++ -c Chicken.cc
g++ -c Cat.cc
g++ -c Pig.cc
g++ -o barn main.o Animal.o Bird.o Chicken.o Cat.o Pig.o Random.o
PS I prefer using Netbeans
A segment fault in the linker suggests a bug with that. This is what I would try if I were to run into this problem.
At the command line do
g++ -o barn main.cc Animal.cc Bird.cc Chicken.cc Cat.cc Pig.cc Random.cc
If that does not work, try variations like:
g++ -o barn main.cc Pig.cc Random.cc Animal.cc Bird.cc Chicken.cc Cat.cc
The order should not matter. This is just the kind of thing I would try with a mystery-meat problem like this.
Recently I need to use zlib in programming on Ubuntu and here I have a problem.
I wrote a small program to test zlib functions and I built it in Eclipse.
I found it can be compiled but there were some linking errors like this:
main.cpp:27: undefined reference to `compress'
main.cpp:38: undefined reference to `uncompress'
What should I do with this? If this is because there is no library file?
Can anyone give some help? Thanks a lot!
MOODY_Y
Plus, here are my building info:
11:59:08 **** Build of configuration Debug for project test_zlib ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: test_zlib
Invoking: GCC C++ Linker
g++ -o "test_zlib" ./main.o
./main.o: In function `main':
/home/hyq/workspace/test_zlib/Debug/../main.cpp:27: undefined reference to `compress'
/home/hyq/workspace/test_zlib/Debug/../main.cpp:38: undefined reference to `uncompress'
collect2: ld return 1
make: *** [test_zlib] error 1
11:59:10 Build Finished (took 1s.715ms)
Try:
sudo apt-get install zlib1g-dev
Also, use -lz on the compile/link command.
You need to link youe source to zlib.Build your code as follows
gcc main.cpp -lz
Why this does not work, file test.c:
#include <event.h>
int main(void)
{
event_init();
return 0;
}
Then:
gcc -o test.o -c test.c runs OK, but
Link:
g++ -o test -levent test.o produces
test.o: In function `main':
test.c:(.text+0x5): undefined reference to `event_init'
collect2: ld returned 1 exit status
So it cannot be linked as C++. How to solve this? I need to link it as C++ and compile as C.
This question has been asked many times. On Linux, you should put libraries after object and source files in the compilation command. So try
g++ -Wall -g -c mytest.cc
g++ -Wall -g mytest.o -levent -o mytest
Avoid calling your test program test which is an existing utility or shell builtin.
As a newbie, remember to always compile with all warnings asked -Wall and for debugging -g and learn to use gdb
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