I am trying to compile a program that uses the OpenSSL library. I had a problem where it couldn't find the header files. I fixed this problem by adding the option -I /usr/local/opt/openssl/include to gcc. After this, I had another problem, which is that the linker does not understand some symbol. This is the error I got:

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

I googled the error, and got a whole lot of results that either only applied to C++, or only applied to programs with multiple modules, etc. Finally, I found what might be a solution to my problem, which is that gcc is hashed to clang on MacOS (I am using El Capitain).

So basically, now I need to find the real gcc executable, then redirect the gcc command to that file with an alias command in my .bashrc file. Where can I find this executable in my filesystem, or do I need to install it from the Internet?

Note: I had this same problem when trying to use the ncurses library.

  • 2
    This is a sledgehammer to crack a walnut, and (ironically) it won't help anyway. The right course of action is simply -lcrypto and an -L for the relevant lib directory. Sadly, you'll end up switching to GCC and having the exact same problem because the compiler was never the problem to begin with. Neither GCC nor clang magically include the OpenSSL header file paths or link libraries from places like /usr/local/opt. You have to add the command line options that specify them. – JdeBP Nov 21 '16 at 18:49

Apple Macos uses clang as it's gcc compiler mainly because of the gcc licensing. You can install GNU gcc using brew. No apple program installs GNU gcc but you can do it manualy and configure to use it by default.

  • Side note: gcc is linked to clang to help developers and scripts that assume every system has gcc. This causes problems for broken scripts that use gcc for C++ code. – Fox Nov 21 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.