在make之后运行可执行文件时,bash引发以下错误:
$ ./prog
-bash: ./prog: cannot execute binary file
我的生成文件:
^{pr2}$我做错什么了?在
更新2:
谢谢你的comment塞尔加亚。在this article的帮助下链接python之后,它就可以工作了。在
更新1:
我在一些注释之后删除了-undefined dynamic_lookup -bundle
标志,因此我在使用Python时遇到了问题。要使用Python.h,我将环境变量设置为以下路径:
CPLUS_INCLUDE_PATH=/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/
2 warnings generated.
g++ -std=c++11 -c datetime.cpp
g++ -std=c++11 -c logger.cpp
g++ -std=c++11 -c WeatherApi.cpp
g++ -std=c++11 -c tinyxml2.cpp
g++ -std=c++11 -c tflower.cpp
g++ -std=c++11 -c tservo.cpp
g++ -std=c++11 -o prog main.o datetime.o logger.o WeatherApi.o tinyxml2.o tflower.o tservo.o
Undefined symbols for architecture x86_64:
"_PyDict_GetItemString", referenced from:
WeatherApi::SayHelloWorld() in WeatherApi.o
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyErr_Print", referenced from:
WeatherApi::WeatherApi(char*, char*) in WeatherApi.o
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyImport_Import", referenced from:
WeatherApi::WeatherApi(char*, char*) in WeatherApi.o
"_PyModule_GetDict", referenced from:
WeatherApi::WeatherApi(char*, char*) in WeatherApi.o
"_PyObject_CallObject", referenced from:
WeatherApi::SayHelloWorld() in WeatherApi.o
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyString_AsString", referenced from:
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyString_FromString", referenced from:
WeatherApi::WeatherApi(char*, char*) in WeatherApi.o
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyTuple_New", referenced from:
WeatherApi::GetAirTemperature() in WeatherApi.o
"_PyTuple_SetItem", referenced from:
WeatherApi::GetAirTemperature() in WeatherApi.o
"_Py_Finalize", referenced from:
WeatherApi::~WeatherApi() in WeatherApi.o
"_Py_Initialize", referenced from:
WeatherApi::WeatherApi(char*, char*) in WeatherApi.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [prog] Error 1
由于您显然想要一个可以直接执行的程序,所以错误之处在于将the ^{} option 指定为g++。这指示它输出应该是Mach-obundle格式的文件。此类文件不能直接执行。它们可以在运行时通过系统的动态链接函数加载到另一个程序中,这些函数可用于实现插件和类似的程序功能。删除此选项。在
-undefined dynamic_lookup
看起来也很可疑。我猜您是从其他Makefile复制了这个和-bundle
选项。如果你不知道它在那里是为了什么,那么你也应该放弃它。在相关问题 更多 >
编程相关推荐