我正在关注此博客,以使用SPM制作C ++软件包: http://ankit.im/swift/2016/05/21/creating-objc-cpp-packages-with-swift-package-manager/
但是在构建时出现此错误:
swift build
'SwiftCpp' /home/karthik/Swift_programs/SwiftCpp: error: target at '/home/karthik/Swift_programs/SwiftCpp/Sources' contains mixed language source files; feature not supported
我正在Ubuntu 18.04 LTS上使用Swift版本4.2.3。
这是代码:
main.cpp
#include <iostream>
#include "cpplib.h"
int main() {
std::cout << cpplib::five();
return 0;
}
cpplib.cpp
#include "include/cpplib.h"
namespace cpplib {
int five(){
return 5;
}
}
cpplib.h
namespace cpplib{
int five();
}
cwrapper.cpp
#include "include/cwrapper.h"
#include "cpplib.h"
int cwrapperfive(){
return cpplib::five();
}
cwrapper.h
#ifdef __cplusplus
extern "C" {
#endif
int cwrapperfive();
#ifdef __cplusplus
}
#endif
main.swift
import cwrapper
print(cwrapperfive())
我该如何解决?