我尝试在osx lion上编译这个cpp代码,但是我收到了一个错误.
#include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
for(int i = 0; i < 10; i++)
{
cout << "hi";
cout << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译:
cc main.cpp
Run Code Online (Sandbox Code Playgroud)
错误:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccBdbc76.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccBdbc76.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccBdbc76.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> …Run Code Online (Sandbox Code Playgroud) 我正在创建一个示例静态库以在我的 iOS 应用程序中使用,但是,在调用静态库的方法时,我遇到了链接器错误:
Undefined symbols for architecture arm64:
"_doMath", referenced from:
_doMathInterface in libTestMain.a(Test.o)
(maybe you meant: _doMathInterface)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
这是静态库的结构:
我有一个头文件 Test.h:
#import <Foundation/Foundation.h>
@interface Test : NSObject
int doMathInterface(int a, int b);
@end
Run Code Online (Sandbox Code Playgroud)
及其实现 Test.m :
#import "Test.h"
#include "PaymentAPI.h"
@implementation Test
int doMathInterface(int a, int b){
return doMath(a, b);
}
@end
Run Code Online (Sandbox Code Playgroud)
在 PaymentAPI.h 中:
#ifndef PaymentAPI_h
#define PaymentAPI_h …Run Code Online (Sandbox Code Playgroud)