Код: Выделить всё
plugin_dir/
`- CMakeLists.txt
`- plugin.cpp
`- plugin.h
`- plugin.swift
Код: Выделить всё
project_name(plugin) # etc.
# ... add swift setup
add_library(${PROJECT_NAME} SHARED project.cpp project.swift)
set_target_properties(${PROJECT_NAME} PROPERTIES Swift_MODULE_NAME "SwiftInterface")
target_compile_options(${PROJECT_NAME} PUBLIC
"$")
# -------------------------------------------------------------
# -- This is pulled from the swift cmake examples from apple --
# -------------------------------------------------------------
_swift_generate_cxx_header(${PROJECT_NAME}
plugin/plugin-swift.h
SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}")
Код: Выделить всё
// project.swift
public func testSwiftCall(_ x: CInt) -> CInt {
print("hello from swift! x=\(x)")
return (x - 1)
}
< /code>
, а затем вызов в файле .cpp (который включает в себя сгенерированный заголовок Swift) < /p>
// project.cpp
#include "plugin/plugin-swift.h"
void someFunction()
{
int x = SwiftInterface::testSwiftCall(123);
}
< /code>
Когда я запускаю сборку xcode, он компилирует как Swift File, так и источник C ++, но сбоя на шаге ссылки.Undefined symbols for architecture arm64:
"SwiftInterface.testSwiftCall(Swift.Int32) -> Swift.Int32", referenced from:
someFunction() in plugin.o
ld: symbol(s) not found for architecture arm64
Подробнее здесь: https://stackoverflow.com/questions/795 ... ary-plugin
Мобильная версия