2012-01-07 4 views
1

言語エンジン(コンパイラまたはインタプリタ、AST、構文、基本セマンティクス)は知っていますが、標準ライブラリはありません(整数型または算術型でないこともあります)。そんなことはありますか?私は、標準ライブラリをC++で実装できるようにしたいと考えています。そんなことがあるの?標準ライブラリを持たない言語エンジン

+0

多分。基本的な構文とセマンティクスを扱うことができれば幸いですが、私はすべての標準ライブラリを自分で作成することができました。もし彼らが '#include 'のようなものが失敗するなら、それは私が後にしていることです。 – Linuxios

答えて

4

GCC(と私は他のコンパイラの多くはかなり確信している)あなたは-nostdinc(も-nostdinc++ C++用)と-nostdlibフラグを、標準ヘッダーおよび/またはライブラリなしで、あなたのコードをビルドすることができます。例えば

$ cat t.cpp 
#include <iostream> 

int main() 
{ 
    std::cout << "ouch" << std::endl; 
} 
$ g++ -nostdinc t.cpp   # Failed compilation 
t.cpp:1:20: error: no include path in which to search for iostream 
t.cpp: In function ‘int main()’: 
t.cpp:5:5: error: ‘cout’ is not a member of ‘std’ 
t.cpp:5:28: error: ‘endl’ is not a member of ‘std’ 
$ g++ -nostdinc++ t.cpp   # Failed compilation 
t.cpp:1:20: fatal error: iostream: No such file or directory 
compilation terminated. 
$ g++ -nostdlib t.cpp   # Compiles, but fails to link 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400158 
/tmp/ccPPO3l6.o: In function `main': 
t.cpp:(.text+0xa): undefined reference to `std::cout' 
t.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' 
t.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' 
t.cpp:(.text+0x1c): undefined reference to `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> >&))' 
/tmp/ccPPO3l6.o: In function `__static_initialization_and_destruction_0(int, int)': 
t.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()' 
t.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()' 
t.cpp:(.text+0x54): undefined reference to `__dso_handle' 
t.cpp:(.text+0x61): undefined reference to `__cxa_atexit' 
collect2: ld returned 1 exit status 

これは、Cライブラリを使用することはできませんカーネルコードのようなものを構築するために使用されます。

巨大なタスクです。標準ライブラリを実装すると幸いです。

関連する問題