Compiling and binding a Swift / Objective-C ++ application through the command line

After adding the C ++ component to my Swift application that compiles and runs through the command line, now I need to compile the C ++ and Objective-C ++ files (* .mm) and associate them with the Swift application.

Makefile:

all: foo-renderer

clean:
  rm -f foo-renderer cpp.o objc.o

cpp.o: FooRenderer/FooRenderer/FooLibrary.cpp
  clang++ -c -o $@ $^

objc.o: cpp.o FooRenderer/FooRenderer/FooLibraryWrapper.mm
  clang++ -c -framework Foundation -o $@ $^

foo-renderer: objc.o FooRenderer/FooRenderer/*.swift
  xcrun -sdk macosx swiftc -import-objc-header FooRenderer/FooRenderer/FooRenderer-Bridging-Header.h -o $@ $^

The compiler cannot handle these errors:

ld: warning: object file (objc.o) was built for newer OSX version (10.12) than being linked (10.9)
Undefined symbols for architecture x86_64:
  "__ZN11FooLibrary23printifyERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE", referenced from:
      -[FooLibraryWrapper printify:] in objc.o
  "__ZN11FooLibrary8optimizeERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE", referenced from:
      -[FooLibraryWrapper optimize:] in objc.o
  "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm", referenced from:
      -[FooLibraryWrapper printify:] in objc.o
      -[FooLibraryWrapper optimize:] in objc.o
  "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev", referenced from:
      -[FooLibraryWrapper printify:] in objc.o
      -[FooLibraryWrapper optimize:] in objc.o
  "__ZSt9terminatev", referenced from:
      ___clang_call_terminate in objc.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in objc.o
  "___gxx_personality_v0", referenced from:
      -[FooLibraryWrapper printify:] in objc.o
      -[FooLibraryWrapper optimize:] in objc.o
      Dwarf Exception Unwind Info (__eh_frame) in objc.o
ld: symbol(s) not found for architecture x86_64

My first instinct was that the standard C ++ libraries were not included. I tried adding these lib flags to the following command, but to no avail:

cpp.o: FooRenderer/FooRenderer/FooLibrary.cpp
  clang++ -c --std=c++14 -lstdc++ -lc++ -stdlib=libstdc++ -o $@ $^

What am I missing?

+4
source share
2 answers

, cpp.o . :

foo-renderer: objc.o FooRenderer/FooRenderer/*.swift cpp.o
      xcrun -sdk macosx swiftc -import-objc-header FooRenderer/FooRenderer/FooRenderer-Bridging-Header.h -o $@ $^

, , ++.

-l... cpp.o , , .

, , , cpp.o objc.o, , . , -framework Foundation, .

+3

objc/clang/swift, , ,

> "__ZN11FooLibrary23printifyERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE",
> referenced from:
>       -[FooLibraryWrapper printify:] in objc.o

, objc printify undefined, FooLibrary:: printify:: basic_string:: char_traits, , , ++, lib++ .

cpp.o: FooRenderer/FooRenderer/FooLibrary.cpp
  clang++ -c --std=c++14 -lstdc++ -lc++ -stdlib=libstdc++ -o $@ $^

/ .

+1

Source: https://habr.com/ru/post/1662914/


All Articles