这是我已经有一年多的问题,我经常会经常回归,这是我一直害怕使用theos(用于构建iOS调整)的主要原因。今天我决定再试一次,我再次进行了测试theos项目并试图用'make'来构建它。这是我试图构建的示例代码:
#include <string>
#include <cstdio>
struct Mine
{
std::string nice;
Mine(std::string p)
{
nice = p;
}
virtual void poop()
{
printf("%s", this->nice.c_str());
}
};
int main()
{
Mine* mine = new Mine("nice");
mine->poop();
return 0;
}
这是我用来在theos中构建它的基本Makefile: GO_EASY_ON_ME = 1 消息=是
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tweak_test
tweak_test_CXXFLAGS = -stdlib=libc++ -std=c++11
tweak_test_LDFLAGS = -stdlib=libc++ -std=c++11
tweak_test_FILES = main.cpp
include $(THEOS_MAKE_PATH)/tweak.mk
请注意,我实际上在构建时指定我想使用libc ++ STL(我必须使用libc ++来构建我正在构建的调整,因为我正在挂钩的应用程序使用它,如果它们会出现运行时冲突是不同的,即由于libc ++的短字符串优化功能,这使得它的字符串在libstdc ++上使用了24个字节而不是8个字节。)
然而,无论我做什么,我总是会遇到与std :: string相关的函数的链接器错误。这是theos的输出,打开了verbose以便打印执行:
Ryans-MacBook-Air:tweak_test ryan$ make
> Making all for tweak tweak_test…
set -o pipefail; (/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going \
internal-library-compile \
_THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=tweak_test _THEOS_CURRENT_OPERATION=compile \
THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes)
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 2 "Compiling main.cpp (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -x c++ -c -I/opt/theos/include -include /opt/theos/Prefix.pch -DTARGET_IPHONE=1 -O0 -Wall -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -fmodules -fcxx-modules -fmodule-name=tweak_test -fbuild-session-file=/Users/ryan/tweaks/tweak_test/.theos/build_session -fmodules-prune-after=345600 -fmodules-prune-interval=86400 -fmodules-validate-once-per-build-session -I/opt/theos/vendor/include -I/opt/theos/include/_fallback -DDEBUG -ggdb -O0 -DTHEOS_INSTANCE_NAME="\"tweak_test\"" -arch armv7 main.cpp -o /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o)
==> Compiling main.cpp (armv7)…
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 3 "Linking tweak tweak_test (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -L/opt/theos/lib -L/opt/theos/vendor/lib -F/opt/theos/vendor/lib -framework CydiaSubstrate -dynamiclib -install_name "/Library/MobileSubstrate/DynamicLibraries/tweak_test.dylib" -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -Wl,-segalign,4000 -multiply_defined suppress -arch armv7 -stdlib=libc++ -std=c++11 -ggdb -O0 -o "/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib" /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o | (grep -v 'usr/lib/dylib1.o, missing required architecture' || true))
==> Linking tweak tweak_test (armv7)…
Undefined symbols for architecture armv7:
"std::string::c_str() const", referenced from:
Mine::poop() in main.cpp.262db704.o
"std::allocator<char>::allocator()", referenced from:
_main in main.cpp.262db704.o
"std::allocator<char>::~allocator()", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in main.cpp.262db704.o
Mine::Mine(std::string) in main.cpp.262db704.o
"std::string::operator=(std::string const&)", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 1
make[2]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [tweak_test.all.tweak.variables] Error 2
请注意,使用libstdc ++构建时,可以正确构建。我认为问题在于与clang而不是clang ++(似乎不是)相关联,或者它与不同的STL链接而不是它与编译时相比(也似乎不是这样) ,基于上面的详细输出)。
如果有人可以帮我解决这个问题,那么一年半的问题终将得到解决。
提前致谢!