1

Here is the code

#include <omp.h>
#include <stdio.h>
int main() {
    #pragma omp parallel
    printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}

which is copy-paste from @prakharjain answer at Installing OpenMP on Mac OS X 10.11.

Compiling with gcc-6 -fopenmp -o a a.cpp returns

Undefined symbols for architecture x86_64:
  "___gxx_personality_v0", referenced from:
      Dwarf Exception Unwind Info (__eh_frame) in ccyHyU08.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Note that if I comment out #pragma omp parallel, then it compiles fine. I installed gcc-6 today following @AlejandroDanielNoel technic as explained at Installing OpenMP on Mac OS X 10.11. I am on Mac OS X 10.12.1. I have 4 logical cores on my machine.

Can you please help me compiling this simple code?


Here is the whole output when compiling with gcc-6 -v -fopenmp -o a a.cpp

Using built-in specs.
COLLECT_GCC=gcc-6
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/lto-wrapper
Target: x86_64-apple-darwin16.1.0
Configured with: ../configure --build=x86_64-apple-darwin16.1.0 --prefix=/usr/local/Cellar/gcc/6.2.0 --libdir=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 6.2.0 --without-multilib' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
Thread model: posix
gcc version 6.2.0 (Homebrew gcc 6.2.0 --without-multilib) 
COLLECT_GCC_OPTIONS='-v' '-fopenmp' '-o' 'a' '-mmacosx-version-min=10.12.1' '-mtune=core2'
 /usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/cc1plus -quiet -v -D__DYNAMIC__ a.cpp -fPIC -quiet -dumpbase a.cpp -mmacosx-version-min=10.12.1 -mtune=core2 -auxbase a -version -fopenmp -o /var/folders/vf/5w2jgk0d0hx582mm92nrk8zm0000gn/T//ccZjzRvK.s
GNU C++14 (Homebrew gcc 6.2.0 --without-multilib) version 6.2.0 (x86_64-apple-darwin16.1.0)
    compiled by GNU C version 6.2.0, GMP version 6.1.1, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../../../../x86_64-apple-darwin16.1.0/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../../../../include/c++/6.2.0
 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../../../../include/c++/6.2.0/x86_64-apple-darwin16.1.0
 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../../../../include/c++/6.2.0/backward
 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/include
 /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks
End of search list.
GNU C++14 (Homebrew gcc 6.2.0 --without-multilib) version 6.2.0 (x86_64-apple-darwin16.1.0)
    compiled by GNU C version 6.2.0, GMP version 6.1.1, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 20fdc54fe5944e0048cbe59ee8edcdd5
COLLECT_GCC_OPTIONS='-v' '-fopenmp' '-o' 'a' '-mmacosx-version-min=10.12.1' '-mtune=core2'
 as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/vf/5w2jgk0d0hx582mm92nrk8zm0000gn/T//ccH3Ixr9.o /var/folders/vf/5w2jgk0d0hx582mm92nrk8zm0000gn/T//ccZjzRvK.s
COMPILER_PATH=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/
LIBRARY_PATH=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../../
COLLECT_GCC_OPTIONS='-v' '-fopenmp' '-o' 'a' '-mmacosx-version-min=10.12.1' '-mtune=core2'
 /usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin16.1.0/6.2.0/collect2 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/ -dynamic -arch x86_64 -macosx_version_min 10.12.1 -weak_reference_mismatches non-weak -o a -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../.. /var/folders/vf/5w2jgk0d0hx582mm92nrk8zm0000gn/T//ccH3Ixr9.o -lgomp -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
collect2 version 6.2.0
/usr/bin/ld -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/ -dynamic -arch x86_64 -macosx_version_min 10.12.1 -weak_reference_mismatches non-weak -o a -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/../../.. /var/folders/vf/5w2jgk0d0hx582mm92nrk8zm0000gn/T//ccH3Ixr9.o -lgomp -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-274.1
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
    /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0
    /usr/local/Cellar/gcc/6.2.0/lib/gcc/6
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/lib
Framework search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "___gxx_personality_v0", referenced from:
      Dwarf Exception Unwind Info (__eh_frame) in ccH3Ixr9.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

1 Answer 1

3

Just try g++-6 instead of gcc-6.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.