Welcome! Log In Create A New Profile

Advanced

linking error

Posted by g_man 
linking error
March 23, 2010 06:01PM
I get this linking error when I try to link two .c files together, I have made no changes to the makefile, which may be the problem, and if so what is my solution. Here is the error, I have checked for spelling mistakes and have found none.
ain.o: In function `main':
c:/Users/Gerik/Desktop/USBBackup/homebrew/aroundplanet/source/main.cpp:74: undefined reference to `createLevel(int, char const*, char, int, int, char, int, int, int)'
c:/Users/Gerik/Desktop/USBBackup/homebrew/aroundplanet/source/main.cpp:75: undefined reference to `setPlanet(int, char, int, int, int, int, int)'
collect2: ld returned 1 exit status
Re: linking error
March 23, 2010 06:14PM
Are createLevel and setPlanet defined in main.cpp or a header main is using? I don't have the source could you give a link or pastie it.
Re: linking error
March 23, 2010 06:19PM
sorry,
in a file included:
void createLevel(int, char const*, char, int, int, char, int, int, int);
void setPlanet(int,char,int,int,int,int,int);
in the other .c file:
#include "levels.h"
#include "string.h"

void createLevel(int lvlnum,const char *name,char diff,int initX,int initY,char planets,int targetX,int targetY,int targetR){
	levelList[lvlnum].difficulty = diff;
	strcpy(levelList[lvlnum].name,name);
	levelList[lvlnum].initX = initX;
	levelList[lvlnum].initY = initY;
	levelList[lvlnum].numPlanets = planets;
	levelList[lvlnum].targetX = targetX;
	levelList[lvlnum].targetY = targetY;
	levelList[lvlnum].targetR = targetR;
}
void setPlanet(int lvlnum,char planetnum,int X,int Y,int R,int D,int G){
	levelList[lvlnum].planetX[planetnum] = X;
	levelList[lvlnum].planetY[planetnum] = Y;
	levelList[lvlnum].planetR[planetnum] = R;
	levelList[lvlnum].planetD[planetnum] = D;
	levelList[lvlnum].planetG[planetnum] = G;
}
main.cjpp:
...
#include "levels.h
...
createLevel(0,"Number One",1,50,50,1,590,430,40);
setPlanet(0,0,490,150,50,300,4000);
...
Re: linking error
March 23, 2010 06:27PM
That helps a little.

try putting at the top of main after #include "levels.h
:

extern void createLevel(int, char const*, char, int, int, char, int, int, int);
extern void setPlanet(int,char,int,int,int,int,int);
Re: linking error
March 23, 2010 06:31PM
nothing, here is the rest of levels.h:
struct Level {
	char name[25];	//Name of level
	char difficulty;//Difficulty of level 1=easy 10=hard
	int initX;		//Initial X Position
	int initY;		//Initial Y Position
	char numPlanets;//Number of planets up to 5
	int planetX[5];	//Planet x positions, up to 5
	int planetY[5];	//Planet y positions, up to 5
	int planetR[5];	//Radius of planet
	int planetD[5]; //Distance gravity affects
	int planetG[5]; //Force of gravity of planet
	int targetX;	//X location of target
	int targetY;	//Y location of target
	int targetR;	//Radius of planet
};
struct Level levelList[20];
void createLevel(int, char const*, char, int, int, char, int, int, int);
void setPlanet(int,char,int,int,int,int,int);
I would post more, but these are the only relevant parts of code.
Re: linking error
March 23, 2010 06:37PM
is levels . c or c++ file .c/.cpp. You may need in main.cpp :

extern "C"
{
extern void createLevel(int, char const*, char, int, int, char, int, int, int);
extern void setPlanet(int,char,int,int,int,int,int);
}

don't know unless I try to build it myself.
Re: linking error
March 23, 2010 10:25PM
fixed it, .cpp was the problem
Sorry, only registered users may post in this forum.

Click here to login