간단한 D 프로그램을 작성하여 간단한 C 라이브러리에 액세스하려고 시도했지만 알 수없는 오류가 있습니다.D 액세스 CentOS 6.5의 C 라이브러리
내 C 코드, Box.c 사용법 #include "Box.h"
int SayHello(int _int)
{
_int ++;
return _int;
}
내 C 헤더 파일, Box.h는
#ifndef BOX_H_INCLUDED
#define BOX_H_INCLUDED
/* export interfaces */
#ifdef __cplusplus
extern "C" {
#endif
int SayHello(int _int);
#ifdef __cplusplus
}
#endif
#endif // BOX_H_INCLUDED
나는
gcc -c Box.c Box.h
컴파일
결과 파일
Box.o
Box.h.gch
내 C 라이브러리에 연결을 시도, 내 D 프로그램의 프로젝트 디렉토리에
내 D 코드
module main;
import std.stdio;
import std.conv;
import std.c.stdio;
import clib;
int main(string[] args)
{
// test external c library
auto s = to!string( SayHello(3)) ;
writefln("my int is "~ s);
readln();
return 0;
}
내 D 인터페이스 파일 (CLIB을)를 배치
module clib;
import std.c.stdio;
extern (C) int SayHello(int _int);
코드 블럭을 사용하여 컴파일 할 때 오류가 발생합니다.
Compiling: hello.d
Linking console executable: bin/Debug/tutorial03-access-c-library4
obj/Debug/hello.o: In function `_Dmain':
/home/hamilton/Tutorial/tutorial03-access-c-library4/hello.d:11: **undefined reference to `SayHello'**
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
오류는 " '에 대한 정의되지 않은 참조의 sayHello'"
나는 그것이 내가 필요로 내가 codeblocks를 사용할 수없는 경우는 매우 고통스러운 것입니다 콘솔$ dmd Box.o hello.d clib.di
에 명령을 사용하여 컴파일 할 때 내가 얻을 오류가 없습니다
디버깅 기능. 감사
업데이트 :
동적 libs와에 대한 링커를 다음과 같이 codeblocks에컴파일러 설정 : 정적 libs가에 대한 GCC -m32 -lrt 링커 :
흠 ... 작동하지 않아 결과가 동일합니다 –
새 빌드가 완료 되었습니까? 로컬에서 시도하면서 소스 코드의 내용이 변경되지 않으면 새 빌드가 수행되지 않습니다. – yaz
그리고 선택한 컴파일러가 Digital Mars D Compiler인지 확인하십시오. – yaz