好吧,我剛剛在一段Windows/Linux共存之後切換到MacOS。我打開一個簡單的文本編輯器,編寫一個簡單的程序來檢查一切是否正常。我知道這個錯誤還有其他線索,但似乎在所有其他情況下,問題都出現在他們程序的特定部分,而這反過來比這更復雜。我只是想了解爲什麼編譯器會說出甚麼是這樣的簡單事情。C++:MacOS Mountain Lion上架構x86_64的未定義符號
#include <iostream>
#include "numeri.h"
int main(void)
{
std::cout << numeri() << std::endl;
return 0;
}
與
//numeri.h
int numeri(void);
和
//numeri.cpp
#include "numeri.h"
int numeri(void)
{
return (3);
}
我從GCC helloworld.cpp得到-Wall是
Undefined symbols for architecture x86_64:
"numeri()", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in cc6WY2MJ.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cc6WY2MJ.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cc6WY2MJ.o
"std::cout", referenced from:
_main in cc6WY2MJ.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 cc6WY2MJ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
兩種情況:
1 - 我忘了如何使用一個簡單的標題(我的前綴,我是一個物理學生,我可以編程它的物理和數值模擬[或者至少,我可以]],但我只是不知道那麼多有關鏈接器編譯器架構和這種東西)
2 - 什麼是錯的
錯誤isn的OS X是特定的,你會在Linux上遇到同樣的問題。 – 2013-04-09 13:59:18
可能的重複[編譯錯誤「未定義的符號」上osx](http://stackoverflow.com/questions/6167040/compilation-error-undefined-symbols-on-osx) – 2013-04-09 14:08:27