main.cpp
#include "a.h"
int main(void)
{
     a_func();
}

a.cpp
#include <stdio.h>
void a_func(void)
{
    printf("hello world\n");
}

a.h
extern void a_func(void);

///--> 주의 extern "C"를 사용하지 않는다. main.cpp , a.cpp 모두 같은 cpp 파일이다.

----------------------
gcc -c -o test.out a.cpp main.cpp 를 하면 다음과 같은 에러가 발생한다.

/tmp/ccSBYZq4.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

gcc는 c,와 c++에 대해서 유연하게 대응하지 못한다, 특히 C++에 대해서
따라서, 명시적으로 g++을 이용하거나 libstdc++을 추가하는 방법으로 해야한다.

g++ -c -o test.out a.cpp main.cpp
gcc -c -o test.out a.cpp main.cpp -lstdc++

<주의 .. -Lstdc++ 안됨. L의 소문자  이어야 한다.>

'리눅스 서버에 대해서' 카테고리의 다른 글

리눅스 쓰레드  (0) 2008.06.19
리눅스에서 스레드 프로그램 컴파일시 옵션  (0) 2008.06.19
Epoll 채팅 서버 소스  (0) 2008.05.25
Select 채팅 서버  (0) 2008.05.25
쓰레드 에코서버  (0) 2008.05.25

+ Recent posts