- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直致力于让服务器/客户端运行一个简单的单线程信使服务。它能够在 Visual Studio 上编译,但是当我尝试通过 makefile 在 Linux 上编译它时,使用命令:make client
,我得到了一个非常大的错误列表。我将提供开头部分,然后是错误列表:
这里说它至少在尝试使用 g++:
g++ -g -c -o client.o client.cc cc client.o -o client client.o: In function
main':
std::allocator::allocator()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:10:
undefined reference toEDIT: I noticed something unusual here. When I call
make client
again without callingmake clean
I get the following:peter@peter-VirtualBox:~/Desktop/CS360/Messaging_Service/messenger$ make client cc client.o -o client client.o: In function
main':
std::allocator::allocator()' Not sure if this is significant or not, but it doesn't mention g++ again.
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:10: undefined reference to
所述错误的片段:
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:7: undefined reference to `std::allocator<char>::allocator()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:7: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:7: undefined reference to `std::allocator<char>::~allocator()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:15: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:18: undefined reference to `std::cout'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:18: 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*)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:18: 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> >&)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:18: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:23: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:23: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:7: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:25: undefined reference to `std::allocator<char>::~allocator()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:25: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:7: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
client.o: In function `Client::Client(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:27: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:27: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:29: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/peter/Desktop/CS360/Messaging_Service/messenger/client.cc:32: undefined reference to `operator new[](unsigned long)'
这让我相信我的 makefile 有错误。我使用 g++,我相信它也可以正常编译,所以我不太确定从这里去哪里。我的 Makefile 是:
CXX= g++ $(CCFLAGS)
MSG-SERVER= server.o
MSG-CLIENT= client.o
OBJS = $(MSG-SERVER) $(MSG-CLIENT)
LIBS =
CCFLAGS = -g
all: msg-server msg-client
msg-server:$(MSG-SERVER)
$(CXX) -o server $(MSG-SERVER) $(LIBS)
msg-client:$(MSG-CLIENT)
$(CXX) -o client $(MSG-CLIENT) $(LIBS)
clean:
rm -f $(OBJS) $(OBJS:.o=.d)
realclean:
rm -f $(OBJS) $(OBJS:.o=.d) server client
# These lines ensure that dependencies are handled automatically.
%.d: %.cc
$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
[ -s $@ ] || rm -f $@'
include $(OBJS:.o=.d)
当我使用 make -d
跟踪 make 时,它会为我提供大量数据。我将发布所提供内容的一些片段,因为老实说我不知道我在看什么:
Trying implicit prerequisite '/usr/include/c++/5/SCCS/s.stdexcept.F'.
Trying pattern rule with stem 'stdexcept'.
Trying implicit prerequisite '/usr/include/c++/5/stdexcept.r'.
Looking for a rule with intermediate file '/usr/include/c++/5/stdexcept.r'.
Avoiding implicit rule recursion.
Avoiding implicit rule recursion.
Avoiding implicit rule recursion.
Trying pattern rule with stem 'stdexcept'.
Rejecting impossible implicit prerequisite '/usr/include/c++/5/stdexcept.l'.
Trying pattern rule with stem 'stdexcept.r'.
Trying implicit prerequisite '/usr/include/c++/5/stdexcept.r,v'.
Trying pattern rule with stem 'stdexcept.r'.
Trying implicit prerequisite '/usr/include/c++/5/RCS/stdexcept.r,v'.
Trying pattern rule with stem 'stdexcept.r'.
Trying implicit prerequisite '/usr/include/c++/5/RCS/stdexcept.r'.
Trying pattern rule with stem 'stdexcept.r'.
Trying implicit prerequisite '/usr/include/c++/5/s.stdexcept.r'.
Trying pattern rule with stem 'stdexcept.r'.
Trying implicit prerequisite '/usr/include/c++/5/SCCS/s.stdexcept.r'.
Trying pattern rule with stem 'stdexcept'.
Rejecting impossible implicit prerequisite '/usr/include/c++/5/stdexcept.F'.
Trying pattern rule with stem 'stdexcept'.
Trying implicit prerequisite '/usr/include/c++/5/stdexcept.m'.
Looking for a rule with intermediate file '/usr/include/c++/5/stdexcept.m'.
Avoiding implicit rule recursion.
Avoiding implicit rule recursion.
Trying pattern rule with stem 'stdexcept'.
Trying implicit prerequisite '/usr/include/c++/5/stdexcept.ym'.
Trying pattern rule with stem 'stdexcept.m'.
Trying implicit prerequisite '/usr/include/c++/5/stdexcept.m,v'.
Trying pattern rule with stem 'stdexcept.m'.
Trying implicit prerequisite '/usr/include/c++/5/RCS/stdexcept.m,v'.
Trying pattern rule with stem 'stdexcept.m'.
Trying implicit prerequisite '/usr/include/c++/5/RCS/stdexcept.m'.
Trying pattern rule with stem 'stdexcept.m'.
就这样直到大约 150~ 行结束时它说它已经完成了目标文件的先决条件:
Finished prerequisites of target file 'server.d'.
Prerequisite 'server.cc' is older than target 'server.d'.
Prerequisite 'server.cc' is older than target 'server.d'.
Prerequisite '/usr/include/stdc-predef.h' is older than target 'server.d'.
Prerequisite 'server.h' is older than target 'server.d'.
Prerequisite '/usr/include/errno.h' is older than target 'server.d'.
Prerequisite '/usr/include/features.h' is older than target 'server.d'.
Prerequisite '/usr/include/x86_64-linux-gnu/sys/cdefs.h' is older than target 'server.d'.
Prerequisite '/usr/include/x86_64-linux-gnu/bits/wordsize.h' is older than target 'server.d'.
Prerequisite '/usr/include/x86_64-linux-gnu/gnu/stubs.h' is older than target 'server.d'.
Prerequisite '/usr/include/x86_64-linux-gnu/gnu/stubs-64.h' is older than target 'server.d'.
Prerequisite '/usr/include/x86_64-linux-gnu/bits/errno.h' is older than target 'server.d'.
对于最后 100 行,它指出:
Must remake target 'server.o'.
g++ -g -c -o server.o server.cc
Putting child 0x13601a0 (server.o) PID 7768 on the chain.
Live child 0x13601a0 (server.o) PID 7768
server.cc: In function ‘int main(int, char**)’:
server.cc:19:17: error: ‘cout’ was not declared in this scope
cout << "server [-p port]" << endl;
^
server.cc:19:47: error: ‘endl’ was not declared in this scope
cout << "server [-p port]" << endl;
^
server.cc: In constructor ‘Server::Server(int)’:
server.cc:34:30: error: ‘>>’ should be ‘> >’ within a nested template argument list
map<string, vector<string>> mappedMessages;
^
server.cc: At global scope:
server.cc:121:36: error: ‘String’ has not been declared
Server::handle_message(int client, String message) {
^
server.cc:121:1: error: prototype for ‘void Server::handle_message(int, int)’ does not match any in class ‘Server’
Server::handle_message(int client, String message) {
^
In file included from server.cc:1:0:
server.h:33:12: error: candidate is: std::__cxx11::string Server::handle_message(int, std::__cxx11::string)
string handle_message(int, string);
^
server.cc:127:35: error: ‘String’ has not been declared
Server::parse_message(int client, String message) {
^
server.cc:127:1: error: prototype for ‘std::__cxx11::string Server::parse_message(int, int)’ does not match any in class ‘Server’
Server::parse_message(int client, String message) {
^
In file included from server.cc:1:0:
server.h:34:12: error: candidate is: std::__cxx11::string Server::parse_message(int, std::__cxx11::string)
string parse_message(int, string);
^
server.cc:190:63: error: ISO C++ forbids declaration of ‘store_message’ with no type [-fpermissive]
Server::store_message(string name, string subject, string data) {
^
server.cc:190:1: error: prototype for ‘int Server::store_message(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’ does not match any in class ‘Server’
Server::store_message(string name, string subject, string data) {
^
In file included from server.cc:1:0:
server.h:36:10: error: candidate is: void Server::store_message(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)
void store_message(string, string, string);
^
server.cc: In member function ‘std::__cxx11::string Server::get_subjects(std::__cxx11::string)’:
server.cc:210:5: error: ‘mappedMessages’ was not declared in this scope
if(mappedMessages.find(name) != mappedMessages.empty()) {
^
server.cc:214:15: error: missing template arguments before ‘it’
for(iterator it = mappedMessages.at(name).begin(); it != mappedMessages.at(name).end(); ++it) {
^
server.cc:214:53: error: ‘it’ was not declared in this scope
for(iterator it = mappedMessages.at(name).begin(); it != mappedMessages.at(name).end(); ++it) {
^
server.cc:214:59: error: ‘mappedMessages’ was not declared in this scope
for(iterator it = mappedMessages.at(name).begin(); it != mappedMessages.at(name).end(); ++it) {
^
server.cc:219:29: error: no match for ‘operator+’ (operand types are ‘std::__cxx11::basic_string<char>’ and ‘int’)
response = response + " " + counter + " " + mappedMessages.at(name).it.front() + "\n";
最佳答案
这里的问题是使用
make client
代替
make msg-client
由于没有客户端目标,默认使用 cc。这显示在原始问题的第一个黄色框中。
关于c++ - 使用 G++, undefined reference std::Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39539752/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!