2010-01-22 4 views
0

내가 사용하는 몇 가지 코드가 :MacOSX에서 g ++에서 gcc 내장 __sync_bool_compare_and_swap을 사용하려면 어떻게해야합니까?

__sync_bool_compare_and_swap 

그것은 리눅스에서 잘 컴파일합니다.

그러나 MacOSX에서 g ++로 컴파일하려고하면 다음과 같이 나타납니다.

error: ‘__sync_bool_compare_and_swap’ was not declared in this scope 

어떻게 수정합니까? (이것은 Mac OSX 10.5.8이므로,이 명령을 가지고 있어야합니다.)

감사합니다!

답변

5

, 당신은 Mac에서 OSCompareAndSwap()를 사용할 수 있습니다.

하지만 플랫폼 간 코드를 사용하는 것이 좋을 것입니다.

0

짐작하면 상자에 해당 기능을 사용하는 Linux에서 사용하는 라이브러리가 없습니다.

은 사용중인 GCC 버전은 무엇

1

(이 함수는 명령을 래핑)? (두 플랫폼 모두). 이것은 GCC에 비교적 최근에 추가 된 것입니다. 당신이 그것을 찾을 수없는 경우 libkern에서

0

OSAtomicAdd32은/OSAtomic.h

2

gcc --version에 gcc 4.1 이상이 표시되지 않으면 명령이없는 것입니다. GCC 4.2과 함께 제공하지만 기본 컴파일러가 명령

난 그냥 눈 표범에 그것을 테스트가없는 4.0이며, 기본 GCC는 4.2 (레오파드의 것입니다)

엑스 코드 3 .1, 그것이 작동합니다.

노트 참조하십시오 Setting GCC 4.2 as the default compiler on Mac OS X Leopard

5

시도는 링커 명령 행 옵션

-march=i686 

를 추가합니다.

-2

기호 __sync_bool_compare_and_swap은 툴체인 (gcc/g ++ 및 기타 컴파일러)에 포함되어 있으며 버전과 관련이 있습니다.

가끔 다음과 같이 나타납니다. ./arm-fsl-linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync -builtins.def : "__sync_bool_compare_and_swap", ./arm-fsl-linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync-builtins.def : "__sync_bool_compare_and_swap_1", ./arm-fsl-linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync-builtins.def : "__sync_bool_compare_and_swap_2", ./arm-fsl-linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync-builtins.def : "__sync_bool_compare_and_swap_4", ./arm-fsl -linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync-builtins.def : "__sync_bool_compare_and_swap_8", ./arm-fsl-linux-gnueabi/4.6.2/lib/gcc/arm-fsl-linux-gnueabi/4.6.2/plugin/include/sync-builtins.def : "__sync_bool_compare_and_swap_16",