Re: gcc Linking problem ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have solved the problem in this way:

$g++ -c stack.cpp
$gcc -c main.c
$g++ -o heloo stack.o main.o

//--- main.c
#include "stack.h"
// #include "stdio.h"


int main(){
	find_in_map();
	return 0;
}


//---stack.h---
#ifdef _cplusplus
extern "C" {
#endif

void find_in_map();
#ifdef _cplusplus
}
# endif



//---stack.cpp---
extern "C"{
#include "stack.h"
}

void find_in_map(){

 	int i;
}





On Sun, Apr 17, 2011 at 11:59, Alireza Haghdoost <haghdoost@xxxxxxxxx> wrote:
> Hello
>
> Would you please let me know why I have this error when I try to link
> my object files:
>
> $Âgcc -c stack.cpp -o stack.o
> $Âgcc -c main.c -o main.o
> $ gcc main.o stack.o -o hello
> main.o: In function `main':
> main.c:(.text+0x7): undefined reference to `find_in_map'
> collect2: ld returned 1 exit status
>
> --// main.c -------------
> #include "stack.h"
> #include "stdio.h"
>
> int main(){
> find_in_map();
> return 0;
> }
> --// stack.h --------------
> void find_in_map();
>
> --// stack.cpp -----------
> #include <stdio.h>
> #include "stack.h"
> void find_in_map(){
> Â printf("hello");
> }
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux