error when compiling giza 1.0.5 - c++

I'm currently trying to compile GIZA++ which I downloaded from http://code.google.com/p/giza-pp/downloads/detail?name=giza-pp-v1.0.5.tar.gz. But everytime I run the make command, the following error always happened:
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
make: *** [GIZA++] Error 1
I really don't know what is wrong, can anyone help me?
I'm using Fedora 14 with g++ version 4.5.1
Thanks for your help

The linker is saying it cannot find the C++ libraries. This suggests that there is something wrong with your GCC installation. Can you post the command line that you use to compile your code. also, can you try compiling this:
#include <iostream>
using namespace std;
int main() {
cout << "hello" << endl;
}
Save it into a file called hello.cpp, and then compile it:
g++ hello.cpp
and tell us what errors you get if any.

Related

Undefined reference to __dso_handle_ - compiling C++ on cygwin

I have a basic Hello World C++ program that I am trying to compile and run on cygwin with g++. The code is:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world." << endl;
return 0;
}
Compiling it with: g++ helloWorld.cpp -o h results in the following error:
/tmp/ccDO1S4J.o:helloWorld.cpp:(.rdata$.refptr.__dso_handle[.refptr.__dso_handle]+0x0): undefined reference to__dso_handle'
collect2: error: ld returned 1 exit status`
I have been reading up on some other threads that indicate that it might be a linker problem and that invoking the linker separately or with verbose output might lead to some more clues.
So, I did:
1. g++ -c helloWorld.cpp -o helloWorld.o (this works - no errors).
2. ld -o h helloWorld.o causes a lot of undefined reference to __main or std::cout etc. errors.
I think this is a linking issue and that I need to link another library perhaps. Any pointers on how to solve this are most welcome.
Re-installing g++ via the installer application on cygwin worked.

Cannot call XInitThreads

I have written an SFML C++ game, and tried to start using threads, but after a while everything crashes. After searching I found out the fix seems to be to call XInitThreads();
but this does not work somehow.
simplified code:
#include <X11/Xlib.h>
int main() {
XInitThreads();
//other stuff
return 1337;
}
The error message I get when i try to compile is "undefined reference to symbol 'XInitThreads'. Could it be that the header file is working but there is no file where that method is implemented?
"undefined reference to symbol" is a linker error, not a compiler error. If you get this message, the compiler has already finished compiled the file into an object file, but is unable to find the shared library which contains the function to link the object file into an executable.
If you're using gcc, it generally means you have to add some -l flags, like so:
$ gcc prog.c -lX11
note that the order of -lX11 in the compiler argument matters, you would get an error if you do this:
$ gcc -lX11 prog.c
/tmp/ccBCxiFT.o: In function `main':
:(.text+0x5): undefined reference to `XInitThreads'
collect2: error: ld returned 1 exit status
You should add link X11 library setting -lX11 to your project. If you are using Eclipse navigate to projectproperties->C/C++ Build->Settings->Tool Settings->GCC Linker->Libraries and add "X11"
Add header-
#include<X11/Xlib.h>
Compile your source code using-
gcc <filename.extension> -lX11
Tested in Ubuntu 16.04 LTS

MinGW and GLUT undefined reference to '_imp____glutInitWithExit#12'

I dabbled in Python for a year, and am starting c++, so I am a noob. I installed MinGW and had everything working fine until I installed freeglut. When I run the following code:
#include <gl/glut.h>
int main()
{
return 0;
}
using:
C:\code\cpp>g++ GLtest1.cpp
I get this:
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x1c): undefined
reference to `_imp____glutInitWithExit#12'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined
reference to `_imp____glutCreateWindowWithExit#8'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined
reference to `_imp____glutCreateMenuWithExit#8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser\AppData\Local\Temp\ccABWOyv.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I installed and re-installed MinGW several times in an attempt to remedy the problem, but to no avail. I tried using
#include <windows.h>
as well. I tried installing the 64 bit .dll files--nothing. If anyone has experienced this before, or is familiar with my problem, some assistance would be welcome. Thank you. I'm guessing I need to do something with "linking", but I really don't see why "glut.h" should be any different than "gl.h", or "glu.h". SO FRUSTRATING!
Update:
I attempted to link a few things. First I did this:
C:\code\cpp>g++ -c -o GLtest1.exe GLtest1.cpp -I"C:\MinGW\include"
and it worked out all right. No errors. Then I tried to link things around and ended up with an error:
C:\code\cpp>g++ -o GLtest1.exe -L"C:\MinGW\lib" -lglut32 -opengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lglut32
collect2.exe: error: ld returned 1 exit status
Any ideas here? glut32.dll exists in both System32 and SysWOW64
You need to link to glut binary:
g++ GLtest1.cpp -lglut32
My case : I switched the lib files and bin file from 64bit to 32bit. And it worked.

Compiling SDL2 with mingw using sublime text 2 errors

I am trying to compile SDL2 with mingw and I get this error:
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.
o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src
/src/libcrt/crt/main.c:91: undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
I googled this error and it looks like I need to specify to link with the -mwindows tag but that doesn't work. Here is my batch file:
g++ -o Game.exe Main/Main.cpp -lmingw32 -LC:\MinGw\include\SDL2\lib\x86 -mwindows -lSDL2main -lSDL2
pause
start /d "C:\Users\Mathew Bergen\Documents\Programming\C++\LD Practice" Game.exe
How do I fix this error?
int main(int argc, char** agv){
//code here
}
For your main function, most of the time I've seen that link error this was the problem. I know I'm really late at posting an answer it's just for other people who have the same problem and stumble upon this page

Can't link libpqxx in MinGW

Using MSYS, I compiled libpq (from compiling postgres). I then compiled libpqxx. Now, I want to create a client that will use libpqxx. libpq seemed to work fine. And, I can compile code with libpqxx. However, linking the libpq client application fails.
Here's my code:
#include <pqxx/pqxx>
#include <iostream>
using namespace std;
using namespace pqxx;
int main() {
connection Conn("dbname=test");
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I added a bunch of libs to the link in a vain hope it would suddenly work. Here's what I have so far:
g++ -IC:\msys\1.0\local\pgsql\include -IC:\msys\1.0\local\include -O0 -g3 -Wall -c -fmessage-length=0 -osrc\Controller.o ..\src\Controller.cpp
g++ -LC:\MinGW\lib -LC:\msys\1.0\local\pgsql\lib -LC:\msys\1.0\local\lib -oController.exe src\Controller.o -lws2_32 -lole32 -lpqxx -lpq -loleaut32 -luuid
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN45_GLOBAL__N__ZN4pqxx16encrypt_passwordERKSsS1_7wait_fdEibP7timeval':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:1434: undefined reference to `select#20'
C:\msys\1.0\local\lib/libpqxx.a(connection_base.o): In function `ZN4pqxx15connection_base12check_resultERKNS_6resultE':
C:/msys/1.0/home/rsolomon/libpqxx/libpqxx-3.0.2/src/connection_base.cxx:420: undefined reference to `select#20'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1770 ms.
I'm thinking the -lws2_32 should've gave me the "select#20". Why is the linker so uppity?
The Unix linker traditionally processes libraries from left to right. So it first considers ws2_32, finds that it has not much use, then goes on to pqxx, and sees that select is undefined and doesn't get defined by any of the later libraries. IOW, try moving ws2_32 to the end of the command line.