簡體   English   中英

嘗試使用boost和ncurses庫編譯程序時出現錯誤

[英]Getting errors when trying to compile program using boost and ncurses libraries

我剛剛開始為任務編寫服務器和客戶端,但是無法編譯我的客戶端代碼。 服務器僅使用boost庫進行編譯就很好,但是在我的客戶端代碼中,我使用了boost和ncurses。

嘗試編譯時,我正在使用g++ battleship_client.cc -lboost_system -lncurses

我瘋狂地用谷歌搜索,但沒有找到解決方案。 我還應該注意,我在Mac上並且正在使用vscode。 我將includePath更改如下:

"includePath": [
            "${workspaceFolder}/**",
            "/usr/local/Cellar/boost/1.68.0_1/",
            "/usr/local/Cellar/ncurses/6.1/"
        ],

battleship_client.cc:

#include <iostream>
#include <string>
#include <vector>
#include <ncurses.h>
#include <boost/asio.hpp>

using namespace std;
using boost::asio::ip::tcp;


void draw_top_matrix(vector<vector<int> > &board, int cur_row, int cur_col) {
    for (int j=0;j<4;j++) {
        move(0,2*j);
        printw("+-");
    }

    move(0,2*4);
    printw("+");

    for (int i=0;i<4;i++) {
        for (int j=0;j<4;j++) {
            move(2*i+1,2*j);
            printw("|");
            move(2*i+1,2*j+1);

            if (board[i][j] == 0) {
                printw(" ");
            } 
            else {
                printw("X");
            }
        }

        move(2*i+1,2*4);
        printw("|");

        for (int j=0;j<4;j++) {
            move(2*i+2,2*j);
            printw("+-");
        }

        move(2*i+2,2*4);
        printw("+");
    }

    move(2*cur_row+1,2*cur_col+1);
}

void init(vector<vector<int> > &board) {
    int rows;
    int cols;
    int cur_row = 0;
    int cur_col = 0;

    for(int i = 0; i < 4; i++) {
        vector<int> temp;
        for(int j = 0; j < 4; j++) {
            temp.push_back(0);
        }
        board.push_back(temp);
    }

    initscr();
    clear();

    getmaxyx(stdscr, rows, cols);

    cbreak();
    keypad(stdscr, TRUE);
    refresh();

    draw_top_matrix(board, 0, 0);
    endwin();
}

int main(int argc, char *argv[]) {
    int port = atoi(argv[3]);
    vector<vector<int> > board;
    boost::asio::io_service my_service;
    tcp::resolver resolver(my_service);

    tcp::socket socket(my_service);
    socket.connect(tcp::endpoint(boost::asio::ip::address::from_string(argv[2]), port));

    init(board);

    return 0;
}

我得到的錯誤:

    In file included from battleship_client.cc:4:0:
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:595:7: error: 'stdscr' is not a type
   int timeout() const
       ^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:595:7: error: expected identifier before ')' token
   int timeout() const
       ^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'std::basic_streambuf<char>::int_type boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::underflow()':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:479:42: error: expected primary-expression before ')' token
             socket().native_handle(), 0, timeout(), ec_) < 0)
                                          ^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'std::basic_streambuf<char>::int_type boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::overflow(std::basic_streambuf<char>::int_type)':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:538:42: error: expected primary-expression before ')' token
             socket().native_handle(), 0, timeout(), ec_) < 0)
                                          ^
/usr/local/include/boost/asio/basic_socket_streambuf.hpp: In member function 'void boost::asio::basic_socket_streambuf<Protocol, Clock, WaitTraits>::connect_to_endpoints(EndpointIterator, EndpointIterator)':
/usr/local/include/boost/asio/basic_socket_streambuf.hpp:656:39: error: expected primary-expression before ')' token
             socket().native_handle(), timeout(), ec_) < 0)

ncurses.h將timeout定義為預處理器宏。 嘗試添加NCURSES_NOMACROS定義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM