g++ 编译.o目标文件出错,不知什么原因?
say.h程序代码:
#include <iostream> void sayhello(void); class Say { private: char * string; public: Say( char * str) { string = str; } void sayThis(const char * str) { std::cout << str << "from a static library\n"; } void sayString(void); }; ~ ~ ~
-----------------------------------------
say.cpp
程序代码:
#include "say.h" void Say::sayString() { std::cout << string << "\n"; } Say librarysay("library instance of Say"); ~ ~
--------------------------------------------
sayhello.cpp
程序代码:
#include "say.h" void sayhello() { std::cout << "hello from a static library\n"; }
+++++++++++++++++++++++++++++++++++++++++++++
以下是报错:
Ubuntu 环境 g++
-virtual-machine:~/桌面/CLearning$ g++ say.cpp
say.cpp:7:41: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
Say librarysay("library instance of Say");
^
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
我想把 say.cpp 和 sayhello.cpp编译成目标文件,然后做成静态库,可是一编译就报错了,新手不知什么原因??