2012-03-07 11 views
0

私のプログラムでこのエラーが何度も発生しています。私は基本を説明するために物を簡略化していますが、まだエラーが発生しています。私は、このライブラリファイルを私のプロジェクトに追加して(libncurses.dylib)、それがいくつかの問題を解決しましたが、この問題は解決しなかったと言われました。ここでApple Mach-O Link Error with curses.h

は私のコードです:

// screen.h

#ifndef screen_h 
#define screen_h 

#define MAC 1 
#define WIN 2 
#define LNX 3 

#ifdef PLATFORM 
#undef PLATFORM 
#endif 

#define PLATFORM MAC 

void screen_erase(); 

#endif 

// screen.c

#include <string.h> 
#include <stdlib.h> 

#include "screen.h" 

#if PLATFORM == MAC 

#include <curses.h> 

void screen_erase(){ 
    erase(); 
} 

#endif 

// main.cppに

#include <iostream> 
#include <curses.h> 
#include "screen.h" 

using namespace std; 

int main(){ 
    screen_erase(); 
} 

そして、ここに私が得るエラーがあります:

Undefined symbols for architecture x86_64: 
    "screen_erase()", referenced from: 
     _main in main.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation 

ここでは何が起こっていますか?

+0

おそらく、各ファイルとリンク行のコンパイルを表示する必要があります。 Joachimが診断したように、C++コンパイラにはCリンケージの関数--extern "C" void screen_erase(void); 'を指定せずにC関数を呼び出すように見えます。そして、それはCコンパイラが理解できないので、あなたもそれを回避する必要があります。 –

答えて

1

これは、CとC++の2つの異なる言語を組み合わせたためです。 screen.hヘッダファイルで

、これに宣言を変更:

#ifdef __cplusplus 
extern "C" { 
#endif 

void screen_erase(); 

#ifdef __cplusplus 
} 
#endif 

screen_erase関数名にname manglingをしないためのC++コンパイラに指示します。

関連する問題