Opened 7 years ago
Closed 6 years ago
#1190 closed defect (fixed)
Mac bundle builds fail when compiling C code
| Reported by: | Tristan Croll | Owned by: | Conrad Huang |
|---|---|---|---|
| Priority: | moderate | Milestone: | |
| Component: | Tool Shed | Version: | |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: | ||
| Notify when closed: | Platform: | all | |
| Project: | ChimeraX |
Description
Clang complains and crashes if you ask it to compile a C file with -std=c++11. While bundle_builder.py currently contains the following:
if sys.platform == "darwin":
libraries = self.libraries
# Unfortunately, clang on macOS (for now) exits
# when receiving a -std=c++11 option when compiling
# a C (not C++) source file, which is why this value
# is named "cpp_flags" not "compile_flags"
cpp_flags = ["-std=c++11", "-stdlib=libc++"]
... it isn't actually used as such, and cpp_flags just gets attached to every compilation. The following amendment to _CLibrary.compile() is one way to tackle it (here I'm killing two birds with one stone by also parallelising it over all available cores):
from concurrent.futures import ThreadPoolExecutor
import os
results = []
with ThreadPoolExecutor(max_workers=os.cpu_count()-1) as executor:
for f in self.source_files:
l = compiler.detect_language(f)
if l == 'c':
preargs = []
elif l == 'c++':
preargs = cpp_flags
else:
raise RuntimeError('Unsupported language for {}'.format(f))
results.append(executor.submit(compiler.compile, [f], extra_preargs=preargs, macros=macros, debug=debug))
#Ensure all have finished before continuing
for r in results:
r.result()
#compiler.compile(self.source_files, extra_preargs=cpp_flags, macros=macros, debug=debug)
Not quite sure how to tackle the same problem with _CModule, though - that's a somewhat different beast.
Attachments (1)
Change History (5)
by , 7 years ago
| Attachment: | bundle_builder.py added |
|---|
comment:1 by , 7 years ago
A few more enhancements/fixes in the attached:
- In
_CLibrary,extra_link_argumentswere not being applied (the argument tocompiler.link_shared_object()should beextra_preargs=extra_link_args, notextra_post_args=extra_link_args) - In Linux, the rpath link argument needs the dollar sign escaped (i.e. it should be
-Wl,-rpath,\$ORIGIN) and it needs to be applied for both_CModuleand_CLibrary - I went ahead and added a
<CompileArgument>field.
comment:2 by , 6 years ago
| Status: | assigned → feedback |
|---|
Has the been resolved as part of another ticket?
comment:3 by , 6 years ago
Yep - I’ve been using the official bundle builder for months now with no issues.
follow-up: 3 comment:4 by , 6 years ago
| Resolution: | → fixed |
|---|---|
| Status: | feedback → closed |
Further bug fixes