# C++ Linker errors



## Ripiz (Apr 22, 2007)

Hello. I just downloaded Code::Block program to compile C++ codes, and as on Dev-C++ I get lnker errors:
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x110): undefined reference to `[email protected]'
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x187): undefined reference to `[email protected]'
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x1ba): undefined reference to `[email protected]'
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x1c9): undefined reference to `[email protected]'
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x208): undefined reference to `[email protected]'
C:\Documents and Settings\Ripiz\Desktop\A_3D_RPG_E153777212003\main.o:main.cpp.text+0x265): undefined reference to `[email protected]'
And much more of them, how to fix them? This program don't have Lnik an Objective C Program option and I don't know how to fix them =[


----------



## Shadow2531 (Apr 30, 2001)

Did you try building in win32 gui mode?

On the command line, it'd look like:

g++ -Wall -Wextra file.cc -o file -O3 -s -mwindows

(plus -llib1 -llib2 etc. if needed)


----------



## Ripiz (Apr 22, 2007)

I got cannot find file.cc error xD
Well when I remove it it says again all those linking errors
If needed I can give source code


----------



## Shadow2531 (Apr 30, 2001)

g++ -Wall -Wextra <your source file that you are trying to build> -o file.exe -O3 -s -mwindows

If you have to link to any libs, use -l.

For example:

g++ -Wall -Wextra <your source file that you are trying to build> -o file.exe -O3 -s -mwindows -lglu32 -lglut32 -lglut -lsdl -lsdlmain

(those are examples)


----------



## Ripiz (Apr 22, 2007)

Wow! Now I get even more errors 
Also my compiler don't have win32 gui modes =[


----------



## Shadow2531 (Apr 30, 2001)

Can you upload the source?


----------



## Ripiz (Apr 22, 2007)

Sure, here it is.
As you will see I didn't made it, I just try to compile it, because I want to learn C++, books don't help at all


----------



## Shadow2531 (Apr 30, 2001)

I downloaded devc++. The -mwindows option is turned on by going to tools -> compiler options -> settings -> linker -> do not create console window = yes

I'll see if I can build the program.


----------



## Ripiz (Apr 22, 2007)

Ok, thanks


----------



## Shadow2531 (Apr 30, 2001)

This is the command I used to build it:


```
g++ -Wall -Wextra main.cpp -o main -O3 -s -mwindows -lwinmm -lglut32 -lglu32 -lsdl -lsdlmain -DWIN32 -lopengl32 -lglaux
```
(some of those parts might not be needed.)

The exe requires glaux.dll.

I got it from this thread:
http://www.atomicmpc.com.au/forums.asp?s=2&c=10&t=1408
(In that thread they said there was a static version that you can link to so the exe doesn't require the dll, but I didn't check that out.

However, c:\dev-cpp\include\gl\gluax.h was missing. I grabbed the file from "c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\gl" (I have the windows sdk installed)

Also, I changed the beginning of main.cpp to:


```
// Movetype: hit 'M' to change. 0 is normal movement, 1 is time based move, frame
// based draw, and 2 is optimal, time based move and a constant FPS of 30.
//#pragma comment(lib, "winmm.lib")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <fstream>
#include <mmsystem.h>
#include <ctime>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
using namespace std;
```
Now, when I load up main.exe, it says to please vote at planetsourcecode.com. Then, the window appears and it's all black with nothing in it. It also stays at 100% cpu usage.

In short, the program is made to be built with Visual C++ express and the Windows SDK.

It's not really meant for Mingw (what devcpp uses).


----------



## Ripiz (Apr 22, 2007)

It's black because it needs some more extra files to create world, but sadly I still can't compile, I tried command line you wrote and there was errors cannot find lsdl and cannot find lsdlmain, so I just removed them. But I still get some errors, but this time they are different

C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0x0): multiple definition of `drawtile(tile)'
.objs\main.o:main.cpp.text+0x100): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0x480): multiple definition of `initcamera(camera&)'
.objs\main.o:main.cpp.text+0x8b4): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0x4b0): multiple definition of `createtile(int, tile&)'
.objs\main.o:main.cpp.text+0x8e4): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0x740): multiple definition of `tileupdate(tile&)'
.objs\main.o:main.cpp.text+0x272c): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0xa90): multiple definition of `creategame(char*, float, float)'
.objs\main.o:main.cpp.text+0x2e04): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0xaa0): multiple definition of `move(camera&)'
.objs\main.o:main.cpp.text+0x2e0a): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0xf80): multiple definition of `DrawGLScene()'
.objs\main.o:main.cpp.text+0x3272): first defined here
C:\DOCUME~1\Ripiz\LOCALS~1\Temp/ccWCaaaa.o:main.cpp.text+0x1420): multiple definition of `ReSizeGLScene(int, int)'
.objs\main.o:main.cpp.text+0x3824): first defined here

It's just a bit of them =\


----------



## Shadow2531 (Apr 30, 2001)

Attached is what I have. It includes a makefile for mingw that I used to build it. It includes glaux.h and glaux.dll. The main include errors in main.cpp were also fixed.

It includes a readme.txt that you can look at.


----------



## Ripiz (Apr 22, 2007)

It still don't work, seems like C++ isn't for me =[


----------



## Shadow2531 (Apr 30, 2001)

What errors do you get now?

Did you try the mingw distro at http://nuwen.net/mingw.html (including setting the windows PATH to include c:\mingw\bin) ?

Did you put glaux.h in the include/gl/ directory?

Did you run the makefile (just type 'make')



> seems like C++ isn't for me =[


It's just crappy code that was probably only tested in VC++. It's also unspefic as to what dependencies you need. They assume you just know.

Maybe we can find some better examples.


----------



## Ripiz (Apr 22, 2007)

Well... It's marked as C++ (general) in that site.
I got those old linker errors, and I already had glaux.h, if I wouldn't it would tell that can't find it


----------

