Search code examples
macosgccassemblymacports

MacPorts GCC compiler, -Wa,-q and "(/opt/local/bin/clang) not installed"


I have a MacPorts GCC compiler installed, and I have a MacPorts Clang installed for the integrated assembler:

$ port installed | egrep -i '(gcc|g\+\+|clang)'
  clang-3.8 @3.8-r262722_1+analyzer (active)
  clang_select @1.0_0 (active)
  gcc49 @4.9.3_0 (active)
  gcc_select @0.1_8 (active)
  libgcc @6.1.0_0 (active)

When I attempt to compile an empty program using the integrated assembler:

$ cat test.cc 
int main(int argc, char* argv[])
{
    return argc;
}

It results in an error:

$ /opt/local//bin/gcc-mp-4.9 -Wa,-q -march=native test.cc -o test.exe
/opt/local/bin/as: assembler (/opt/local/bin/clang) not installed

And:

$ ls /opt/local/bin/clang
ls: /opt/local/bin/clang: No such file or directory

It appears there more to using the integrated assembler than just -Wa,-q. If I omit -Wa,-q, then the real program experiences a failure similar to How to use AVX/pclmulqdq on Mac OS X.

How do I tell the GCC compiler to use the integrated assembler from the installed Clang? I.e., clang++ -Wa,-q -Wa,as=/opt/local/bin/clang-mp-3.8

Or, do these things need to be installed in pairs where the version numbers matter? I.e., something like GCC 4.9 (JAN 2016) needs Clang 3.7 (JAN 2016)?

Or, what compiler does MacPorts normally place at /opt/local/bin/clang? E.g., Clang 3.5 is normally placed at /opt/local/bin/clang


For completeness, this MacBook has MacPorts, but its not on path. I use the MBP for OS X testing, and a second role is [soon to be] MacPorts testing. However, I've refrained from putting MacPorts on path to avoid tainting OS X testing.


Solution

  • You can simply do sudo port select clang mp-clang-3.8. I did not like this, because it makes this the default when simply calling clang (only if MacPorts is on the PATH, of course).

    What I ended up doing is to replace /opt/local/bin/as with the following simple script:

    #!/bin/sh 
    clang -c -x assembler $@ - 
    

    And then I don't use the -Wa,-q arguments to gcc.