2013-06-17 5 views
0

일부 병렬 연산을 수행하기 위해 내 Linux 컴퓨터 (CentOS 6.4)에 MPICH (ver 3.0.4)를 설치했습니다. 나는이 명령을 내 MPICH 설치를 테스트하기 위해 (예를 들어 MPICH 설치 패키지와 함께 제공) "pmandel.c"를 컴파일하려고 :는 mpicc로 pmandel.c를 컴파일 할 수 없습니다.

mpicc pmandel.c -o pmandel.out 

하지만 이러한 오류 반환 :

pmandel.c: In function ‘main’: 
pmandel.c:279: warning: passing argument 2 of ‘bind’ from incompatible pointer type 
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’ 
pmandel.c:282: warning: passing argument 2 of ‘bind’ from incompatible pointer type 
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’ 
pmandel.c:296: warning: passing argument 2 of ‘getsockname’ from incompatible pointer type 
/usr/include/sys/socket.h:119: note: expected ‘struct sockaddr * __restrict__’ but argument is of type ‘struct sockaddr_in *’ 
/tmp/cclNv8nA.o: In function `exponential_complex': 
pmandel.c:(.text+0x2fc2): undefined reference to `exp' 
pmandel.c:(.text+0x2fd1): undefined reference to `cos' 
pmandel.c:(.text+0x2fe5): undefined reference to `sin' 
/tmp/cclNv8nA.o: In function `absolute_complex': 
pmandel.c:(.text+0x3330): undefined reference to `sqrt' 
collect2: ld returned 1 exit status 

과 출력되지 않습니다. 또한 "mpiC++"로 시도, "mpiCC"mpicxx "아무 소용이 ...하지만 모두.

나는

+0

다음은 경고 (오류 제외)이며 소스 코드를 변경할 수 있습니다 전자 코드를 제거하십시오. 'pmandel.out'이 생성되어 실행 가능해야한다고 생각합니다. –

+0

내 게시물에 오류 중 일부가 누락되어 편집했습니다. thanks – gnome

+0

링커에 의해 트리거 된 오류는 라이브러리가 누락되었습니다. 스위치'-lm'을 사용하여 다시 컴파일하십시오. – Spiros

답변

1

@Spiros 당신이 -lm을 추가 할 필요가 정확한지?이 문제를 해결하기 위해해야 ​​할 일 당신의 명령에 당신이 지정하는 곳이 중요합니다.

"명령에서 당신이이 옵션을 쓰는 점이 다릅니다. 링커는 라이브러리와 오브젝트 파일을 지정된 순서대로 검색하고 처리합니다. 따라서 'foo.o -lz bar.o'는 foo.o 파일 다음에 bar.o 앞에 라이브러리 'z'를 검색합니다. bar.o가 'Z'에서 함수를 참조하는 경우, 그 기능을로드 할 수 없습니다. "

http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html를 참조하십시오.

그것은 pmandel.out 후 제공됩니다.

mpicc pmandel.c -o pmandel.out -lm 

을 다른 방법으로는 mpich 예제 디렉토리에 포함 된 Makefile을 사용하여

을 입력 할 수 있습니다.
make pmandel 
+1

내가 참조한 GCC 페이지에서 : "명령에서이 옵션을 쓰는 위치가 달라 지므로 링커는 지정된 순서대로 라이브러리와 개체 파일을 검색하고 처리합니다. 따라서 'foo.o -lz bar.o '는 foo.o 파일 다음에 bar.o 앞에있는 라이브러리'z '를 검색합니다. bar.o가'z '의 함수를 참조하면 해당 함수가로드되지 않을 수 있습니다. " – kraffenetti

+1

또한 mpicc는 GCC 규칙이 적용되는 기본 C 컴파일러의 편리한 래퍼 일뿐입니다. – kraffenetti

+0

makefile을 보면,'-lm'뿐만 아니라'-lpthread -lmpi'도 추가해야합니다. – Urhixidur

관련 문제