Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86_64-apple-darwin13.4.0-clang fails with "unsupported file format" error #9096

Closed
mcflugen opened this issue Apr 4, 2018 · 21 comments
Closed

Comments

@mcflugen
Copy link

mcflugen commented Apr 4, 2018

When I try to compile a program with x86_64-apple-darwin13.4.0-clang (4.0.1 build 10), I get the following error,

ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

I suspect this has something to do with Xcode 9.3 as I only started seeing this problem after upgrading to 9.3. In addition, things are working just fine on another machine with Xcode 9.0. I notice that the above unsupported file format seems to refer to tapi-tbd-v3.

To reproduce the problem I simply try to compile the following,

/* main.c */
int main() {
  return 0;
}

with

$ x86_64-apple-darwin13.4.0-clang main.c

and I get the above error. If I compile with clang (again 4.0.1) it compiles without error.

@mingwandroid
Copy link

You probably need to use an older macOS SDK.

@mingwandroid
Copy link

You can force our toolchain to use a specific SDK via the env. var CONDA_BUILD_SYSROOT

@mingwandroid
Copy link

When you run clang your system linker gets used. This is @(#)PROGRAM:ld PROJECT:ld64-351.8

When you run x86_64-apple-darwin13.4.0-clang our linker gets used. This is @(#)PROGRAM:ld PROJECT: ld64-274.2

AFAICT, Apple have not released the source-code for version 351.8 so there's nothing I can do about this at present.

@mcflugen
Copy link
Author

mcflugen commented Apr 4, 2018

Thanks @mingwandroid. I installed MacOSX10.9.sdk from phracker/MacOSX-SDKs and that seemed to do the trick.

I assume that this will be something that will eventually be fixed (but not until (if?) Apple releases the source code for this version)?

@mingwandroid
Copy link

While it'd be nice to support any SDK the user wants, it's not something we're in control of, nor is it a pressing need for building packages for Anaconda Distribution, in fact, supporting newer SDKs would lead to conda packages being released (by other people) that are not compatible with macOS 10.10 (which is the minimum supported version for AD right now).

I know there are meant to be ways of using newer SDKs with a different MACOSX_DEPLOYMENT_TARGET but I've never found that to be very reliable (or at all reliable).

We do do this though to an extent for a single package. Qt 5.9.4 needs to be built with macOS SDK 10.11 and we target 10.10, still this isn't something I'm comfortable with in general.

@tjd2002
Copy link

tjd2002 commented Jul 12, 2018

I had the same linking error when using the SDK provided with Xcode 9.4 (10.13); I found I could successfully link using any of the SDKs from phracker/MacOSX-SDKs repo (I tested 10.9, 10.10, 10.11, 10.12 and 10.13).

So it's not necessary to go all the way back to 10.9, if you have other reasons for wanting to use a more recent version of the SDK

@aisync
Copy link

aisync commented Oct 26, 2018

I think I'm having this same issue but too unfamiliar with the coding process to fix as has been suggested. If I'm not mistaken this sounds like the same problem everyone else is having. I'm getting the error just from running:

install.packages("devtools")

Just a snippet of the output messages looks like:
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd

Then below that:

ld: symbol(s) not found for architecture x86_64 clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makevars:11: px] Error 1 ERROR: compilation failed for package ‘ps’

Anaconda's version of RStudio. I have RStudio installed by itself too and I was using that for a long time before installing Anaconda. Sorry for to inundate but what exactly is the solution by path of least resistance? I don't intend on using Rstudio by itself so I can uninstall that if it's conflicting with anything.

@yarcowang
Copy link

@aisync Have you resolved this?

Mine's even strange... when executing in R studio, I got errors:

> install.packages('ps', verbose=TRUE)
system (cmd0): /usr/local/anaconda3/lib/R/bin/R CMD INSTALL
trying URL 'https://mirrors.shu.edu.cn/CRAN/src/contrib/ps_1.3.0.tar.gz'
Content type 'application/octet-stream' length 261887 bytes (255 KB)
==================================================
downloaded 255 KB

foundpkgs: ps, /var/folders/21/fzkzlt1d1tgglst_zj71jxsh0000gn/T//RtmpHWts8n/downloaded_packages/ps_1.3.0.tar.gz
files: /var/folders/21/fzkzlt1d1tgglst_zj71jxsh0000gn/T//RtmpHWts8n/downloaded_packages/ps_1.3.0.tar.gz
* installing *source* package ‘ps’ ...
** package ‘ps’ successfully unpacked and MD5 sums checked
** libs
x86_64-apple-darwin13.4.0-clang -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -I/usr/local/anaconda3/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix  -Wall px.c -o px
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib/libSystem.tbd
Undefined symbols for architecture x86_64:
  "___error", referenced from:
      _echo_from_fd in px-a28e1e.o
...
     (maybe you meant: _write_to_fd)
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makevars:11: px] Error 1
ERROR: compilation failed for package ‘ps’
* removing ‘/usr/local/anaconda3/lib/R/library/ps’
* restoring previous ‘/usr/local/anaconda3/lib/R/library/ps’
Warning in install.packages :
  installation of package ‘ps’ had non-zero exit status

But run when under the terminal, I got success:

yarco@heavens ~$ /usr/local/anaconda3/lib/R/bin/R CMD INSTALL /var/folders/21/fzkzlt1d1tgglst_zj71jxsh0000gn/T//RtmpHWts8n/downloaded_packages/ps_1.3.0.tar.gz
* installing to library ‘/usr/local/anaconda3/lib/R/library’
* installing *source* package ‘ps’ ...
** package ‘ps’ successfully unpacked and MD5 sums checked
** libs
x86_64-apple-darwin13.4.0-clang -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -I/usr/local/anaconda3/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix  -Wall px.c -o px
x86_64-apple-darwin13.4.0-clang -I"/usr/local/anaconda3/lib/R/include" -DNDEBUG   -D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -I/usr/local/anaconda3/include   -fPIC  -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -I/usr/local/anaconda3/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix  -c init.c -o init.o
...
/anaconda3/lib/R/lib -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/usr/local/anaconda3/lib -L/usr/local/anaconda3/lib -o ps.so init.o api-common.o common.o extra.o dummy.o posix.o api-posix.o macos.o api-macos.o arch/macos/process_info.o -L/usr/local/anaconda3/lib/R/lib -lR -Wl,-framework -Wl,CoreFoundation
ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking.
ld: warning: -pie being ignored. It is only used when linking a main executable
installing via 'install.libs.R' to /usr/local/anaconda3/lib/R/library/ps
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (ps)
yarco@heavens ~$

I don't know what's going on. It seems one goes to use XCode libSystem.tbd, one goes to use system's CoreFoundation.tbd.

@aisync
Copy link

aisync commented Jan 30, 2019

@yarcowang this's been a long standing issue on my end. I was able to find
Anaconda R-PS

After running conda install -c conda-forge/label/gcc7 r-ps

I've gotten packages installed that require the dependency. But I still don't know what's going on either. If anybody has a solution that'd be great.

@ihnorton
Copy link

@aisync @yarcowang and anyone else who hits this:

  • download MacOSX10.10 SDK from Apple (or google "MacOSX sdks") as ~/Downloads/MacOSX10.10.sdk.FILE (some filename)
  • tar xf [~/Downloads/MacOSX10.10.sdk.FILE] -C /opt
  • edit $HOME/.condarc and add these lines:
    conda_build:
      config_file: ~/.conda/conda_build_config.yaml
    
  • create $HOME/.conda/conda_build_config.yaml and add these lines:
    CONDA_BUILD_SYSROOT:
      - /opt/MacOSX10.10.sdk        # [osx]
    

See also: https://docs.conda.io/projects/conda-build/en/latest/source/resources/variants.html?highlight=variants#creating-conda-build-variant-config-files

@aisync
Copy link

aisync commented Mar 1, 2019

@ihnorton Much thanks. I gave this a go on a fresh computer I fortunately had the advantage of testing it on. After following above instructions it didn't seem to fix the exit status following the series of compilation errors. I'll include the output, one run on R-Studio and the other on R via Terminal -- after adjusting the above configs.

It's possible I didn't successfully use the downgraded SDK if the procedure is more involved then what your instructions included? Anybody else find this to fix the compile error?

@mingwandroid you've helped me with this in the past. The end result was to install as many dependencies from Conda rather than through CRAN via R. The latter will more often than not exit with zero status and tons of compiling errors. I've since followed the instructions below with MacOSX10.10.sdk hoping I'd be able to mitigate lengthy builds via skeleton or to find Conda alternative available. I pasted the output to a Pastebin below. If you take a quick glance at that I think you'll see what I might be referring to. Those outputs are post the 10.10 downgrade.

https://pastebin.com/z4P8TLfi
https://pastebin.com/bYYfswW8

The general error will be something along the lines of (above link is more complete)

ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makevars:11: px] Error 1
ERROR: compilation failed for package ‘ps’
* removing ‘/Users/[user]/anaconda3/envs/testenv/lib/R/library/ps’
ERROR: dependency ‘ps’ is not available for package ‘processx’
* removing ‘/Users/[user]/anaconda3/envs/testenv/lib/R/library/processx’
ERROR: dependency ‘processx’ is not available for package ‘callr’
* removing ‘/Users/[user]/anaconda3/envs/testenv/lib/R/library/callr’

@aisync
Copy link

aisync commented Mar 1, 2019

@aisync @yarcowang and anyone else who hits this:

  • download MacOSX10.10 SDK from Apple (or google "MacOSX sdks") as ~/Downloads/MacOSX10.10.sdk.FILE (some filename)
  • tar xf [~/Downloads/MacOSX10.10.sdk.FILE] -C /opt
  • edit $HOME/.condarc and add these lines:
    conda_build:
      config_file: ~/.conda/conda_build_config.yaml
    
  • create $HOME/.conda/conda_build_config.yaml and add these lines:
    CONDA_BUILD_SYSROOT:
      - /opt/MacOSX10.10.sdk        # [osx]
    

See also: https://docs.conda.io/projects/conda-build/en/latest/source/resources/variants.html?highlight=variants#creating-conda-build-variant-config-files

I had to create /opt directory because the command was outputting an error:
tar: could not chdir to '/opt'

I wasn't sure if this was a universal directory or not, but thought it was worth mentioning.

@aisync
Copy link

aisync commented Mar 3, 2019

@ihnorton I'm not familiar with much of the coding and use R/Conda mainly for statistical packages.
Sorry for the basic question. But having downgraded the SDK to 10.10, is it going to stay at that if I don't take additional steps to upgrade in the future? Essentially moving forward are there measures I'll need to take for any future updates?

@tjd2002 you were able to use the same 10.13 SDK downloaded from phracker and it resolved the issue?

Appreciate all the help

@ihnorton
Copy link

ihnorton commented Mar 3, 2019

Setting CONDA_BUILD_SYSROOT: tells conda-build which SDK to use. So as long as the config and condarc files still set CONDA_BUILD_SYSROOT: to the 10.10 SDK, that SDK version will used used when compiling within conda-build.

@mingwandroid
Copy link

will used used when compiling within conda-build.

It's stronger than that. The pointed to SDK will be used when using our compilers and/or linkers, any calls to -isysroot or -sysroot will be ignored.

@mingwandroid
Copy link

@aisync,

But having downgraded the SDK to 10.10, is it going to stay at that if I don't take additional steps to upgrade in the future? Essentially moving forward are there measures I'll need to take for any future updates?

The SDK version is nothing to do with what version of macOS you are running. These SDKs are just folders containing headers and libraries used for compiling and linking against when building software. We use old SDKs so that our software works on a large range of macOS systems (i.e. old ones work too).

@aisync
Copy link

aisync commented Mar 3, 2019

@aisync,

But having downgraded the SDK to 10.10, is it going to stay at that if I don't take additional steps to upgrade in the future? Essentially moving forward are there measures I'll need to take for any future updates?

The SDK version is nothing to do with what version of macOS you are running. These SDKs are just folders containing headers and libraries used for compiling and linking against when building software. We use old SDKs so that our software works on a large range of macOS systems (i.e. old ones work too).

Much appreciated @mingwandroid . Just to confirm: Undoing the process by deleting config file in /opt etc... would return to using the latest standard SDK as normal?

@mingwandroid
Copy link

would return to using the latest standard SDK as normal?

In what sense do you mean 'using'?

The env var is only ever queried by the anaconda MacOS compiler and linker. Outside of this the variable and the folder it points to are irrelevant.

@aisync
Copy link

aisync commented Mar 3, 2019

would return to using the latest standard SDK as normal?

In what sense do you mean 'using'?

The env var is only ever queried by the anaconda MacOS compiler and linker. Outside of this the variable and the folder it points to are irrelevant.

When you say the variable and folder it points to, you're specifically referring to the added lines in the config files?

It's superfluous. But if I was to delete the added lines:

conda_build:
 config_file: ~/.conda/conda_build_config.yaml

as well as the $HOME/.conda/conda_build_config.yaml created config files -- it'd return to it's default state. Just a presumption I made.

zhihaoy added a commit to zhihaoy/doctest that referenced this issue Jul 26, 2019
Problem: ContinuumIO/anaconda-issues#9096

For unclear reason, only the C compiler fails CMake's compiler tests.
But since doctest is a header-only C++ library, we can just allow it
to be built with miniconda3's toolchain on MacOSX under SDK>=10.14.

This change can also reduce compiler testing time.
onqtam pushed a commit to doctest/doctest that referenced this issue Aug 5, 2019
Problem: ContinuumIO/anaconda-issues#9096

For unclear reason, only the C compiler fails CMake's compiler tests.
But since doctest is a header-only C++ library, we can just allow it
to be built with miniconda3's toolchain on MacOSX under SDK>=10.14.

This change can also reduce compiler testing time.
@jmarshall
Copy link

AFAICT, Apple have not released the source-code for version 351.8 so there's nothing I can do about this at present.

It would appear from that page that source code for 351.8 and a later version have now been released (since November 2018).

@ghacosta
Copy link

ghacosta commented Oct 7, 2020

I'm using Anaconda Navigator and I had these kind of problem while trying to install packages like "arules" inside Rstudio.

I followed @ihnorton answer but I figured out that inside Rstudio CONDA_BUILD_SYSROOT env var was set to the original sdk, to override this you need to update .Rprofile like this:

Sys.setenv(CONDA_BUILD_SYSROOT = "/opt/MacOSX10.10.sdk")

After that you are good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants