Compiling

錯誤:未在此範圍內聲明“TCP_NODELAY”

  • October 8, 2017

我正在嘗試在 Ubuntu 16.04 中編譯 ChatScipt v7.55。但是當我使用make server命令時,我得到了這個錯誤:

evserver.cpp: In function ‘int settcpnodelay(int)’:
evserver.cpp:263:40: error: ‘TCP_NODELAY’ was not declared in this scope
    return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*) &on, sizeof(on));
                                       ^
Makefile:110: recipe for target 'evserver.o' failed
make: *** [evserver.o] Error 1

這是命令的完整結果:

************ LINUX VERSION ************
g++ -c  -std=c++11 -Wall  -funsigned-char  -Wno-write-strings -Wno-char-subscripts -Wno-strict-aliasing  -DLOCKUSERFILE=1  -DEVSERVER=1 -DEVSERVER_FORK=1  -DDISCARDPOSTGRES=1 -DDISCARDMONGO=1 -DDISCARDMYSQL=1  -Ievserver evserver.cpp -o evserver.o
evserver.cpp: In function ‘int settcpnodelay(int)’:
evserver.cpp:263:40: error: ‘TCP_NODELAY’ was not declared in this scope
    return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*) &on, sizeof(on));
                                       ^
Makefile:110: recipe for target 'evserver.o' failed
make: *** [evserver.o] Error 1

有什麼問題,我該如何解決?

我通過添加 #include <netinet/tcp.h> 上面的“evserver.cpp”文件解決了這個問題

引用自:https://unix.stackexchange.com/questions/396714