未定义的符号链接器错误
C++ - Undefined Symbols Linker Error - Xcode
我有三个c++文件,我得到一个非常烦人的c++链接器错误。下面是错误:
Undefined symbols for architecture x86_64:
"tiled::debug::log(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main.o
error_callback(int, char const*) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的文件:
main.cpp
#include "debug.hpp"
#include <GLFW/glfw3.h>
using namespace tiled;
void error_callback(int error, const char* description);
int main(int argc, char* argv[])
{
debug::log("Initializing");
glfwSetErrorCallback(error_callback);
debug::log("Initializing GLFW...");
if (!glfwInit())
{
debug::log("Failed to initialize GLFW!");
glfwTerminate();
return -1;
}
debug::log("Done");
debug::log("Exiting program!");
glfwTerminate();
return 0;
}
void error_callback(int error, const char* description)
{
std::string error_code;
error_code.append("GLFW error ");
error_code.append(std::to_string(error));
debug::log(error_code);
debug::log(description);
}
debug.hpp
#ifndef TILED_DEBUG_HPP
#define TILED_DEBUG_HPP
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
namespace tiled
{
class debug {
private:
static std::vector<std::string> data;
static std::ofstream log_file;
public:
static void log(const std::string& msg);
static int write_logs();
};
}
#endif /* TILED_DEBUG_HPP */
, debug.cpp
#include "debug.hpp"
namespace tiled
{
void debug::log (const std::string& msg)
{
// Log to the console
std::cout << msg << std::endl;
// Add to the data we will put in the log file.
data.push_back(msg);
}
int debug::write_logs()
{
std::string data_str;
/*
We get the system time here. This is because we want to name each log
after what time the log file was made.
*/
std::time_t result = std::time(nullptr);
std::string time = std::asctime(std::localtime(&result));
data_str.append("n");
data_str.append(time);
// Put the contents of the data vector into the string we append to file
for (std::string str : data)
{
data_str.append("n");
data_str.append(str);
}
log_file.open(time.c_str(), std::ios::app);
if (log_file.is_open())
{
log_file << data_str;
log_file.close();
}
else
{
std::cout << "Error: Couldn't write log file!" << std::endl;
return 1;
}
return 0;
}
}
似乎没有定义函数日志,但我在debug.cpp文件中定义了它。我已经研究了几个小时了…有人能帮我吗?
另外,如果有帮助的话,这里是Xcode在构建程序时使用的命令:
Ld/Users/home/Library/Developer/Xcode/DerivedData/tiled-bhqwfqpsuugzhkagbmrhebnbgnpb/Build/Products/Debug/tiled normal x86_64cd/用户/home/文件/瓦出口MACOSX_DEPLOYMENT_TARGET = 10.10/应用程序/Xcode-beta.app/内容/开发/工具链/XcodeDefault。xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.11. xctoolchain/usr/bin/clang++ -arch x86_64sdk -L/Users/home/Library/Developer/Xcode/DerivedData/tileed -bhqwfqpsuugzhkagbmrhebnbgnpb/Build/Products/Debug -L/usr/local/lib -F/Users/home/Library/Developer/Xcode/DerivedData/tileed - bhqwfqpsuugzhkagbmrhebngnpb/Build/Products/Debug -filelist/Users/home/Library/Developer/Xcode/DerivedData/tileed - bhqwfqpsuugzhkagbmrhebngnpb/Build/Intermediates/tileed . Build/Debug/tileed . Build/Objects-normal/x86_64/tileed . BuildLinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ - lglfw3.1 -framework OpenGL -Xlinker -dependency_info -Xlinker/Users/home/Library/Developer/Xcode/DerivedData/tiled-bhqwfqpsuugzhkagbmrhebnbgnpb/Build/Intermediates/tiled.build/Debug/tiled.build/Objects-normal/x86_64/tiled_dependency_info.dat -o/Users/home/Library/Developer/Xcode/DerivedData/tiled- bhqwfqpsuugzhkagbmrhebngnpb/Build/Products/Debug/tile
为了解决这个问题,我去掉了。cpp文件,只制作了这些内联函数。因为这只是一个变通方法,所以我不会选择这个作为答案
- 体系结构x86_64的未定义符号:链接器错误
- 如何防止 CMake 在构建时(而不是在安装时)为共享库创建符号链接?
- 如何将空文件夹和符号链接添加到存档 - libarchive
- JNI 不满意链接错误: 动态链接库 (DLL) 初始化例程失败
- CMake / 错误时链接 libfreeimage / libtiff.
- 可能的 GCC 链接器错误会导致将弱符号和局部符号链接在一起时出错
- 单一实例对象的未解决外部符号链接错误
- 导出类静态常量的未解决外部符号链接错误(仅限某些项目)
- OpenCV 模块作为符号链接会导致 cmake 错误
- 建筑x86_64的未定义符号:链接错误
- 带有正确包含保护的C++重复符号链接器错误
- 链接器错误尝试链接libFlurryAds时出现重复符号
- 将类从应用程序解决方案移动到静态库解决方案会产生无法解决的外部符号链接错误
- Visual Studio 2015 C++ 未解析的外部符号链接错误
- 设置为 'default' 时"compile as"外部符号链接错误
- 错误 LNK2019:未解析的外部符号链接器找不到 DLL
- 为什么这种特殊情况会导致符号链接错误
- 如何解决动态链接XCode项目到lib4cxx库时的单符号链接错误
- 未定义的符号链接器错误
- C++:避免重复的符号链接器错误