google-deepmind/open_spiel

I can't compile open_spiel in c++

LucasCelestinoSE opened this issue · 2 comments

I wrote this code to test. ( I'm a student with a technological initiation project on my university, i'm not a pro with c++ and i'm really difficulties here)
`

#include <iostream>
#include <memory>
#include <vector>
#include "open_spiel/spiel.h"
#include "open_spiel/games/tic_tac_toe/tic_tac_toe.h"

using namespace std;
using namespace open_spiel;

int main() {
   auto game = LoadGame("tic_tac_toe");
   auto state = game->NewInitialState();

    while (!state->IsTerminal()) {
       cout << "Tabuleiro atual:\n" << state->ToString() << endl;

       Player current_player = state->CurrentPlayer();
      cout << "Turno do jogador " << current_player << endl;

      vector<Action> legal_actions = state->LegalActions();
      Action action = legal_actions[rand() % legal_actions.size()];

      cout << "Jogador " << current_player << " jogou na posição " << action << endl;
      state->ApplyAction(action);
}

 return 0;

}
`
But for some reason that i'm not know why, the dependencies of spiel.h dont working when i run
g++ test.cpp -o test
That error occurs > non-existing file or directory
image

I don't have a good understanding of how the c++ build works properly, or else I installed open_spiel wrongly as some python tests didn't pass, although the c++ builds are working without any problems. (I use python's openSpiel with the pip package)

Sorry for my English, I don't speak it fluently

Hi @LucasCelestinoSE,

Ah yes, this is one of the dependencies.

There are two ways to use C++ with OpenSpiel.

Opiton 1: Build OpenSpiel from source and use CMake. Follow the instructions here to first build OpenSpiel from source. This will download the necessary dependencies and build OpenSpiel. Then add your own binaries or source in the CMakeLists.txt files (the same way the OpenSpiel source/binaries are added). If you anticipate changing any of the core OpenSpiel code, this is probably the option you want.

Option 2: Build OpenSpiel as a stand-alone C++ library. Follow the instructions here. Then when you compile, dynamically link against the OpenSpiel shared library (as shown in the example on that page). If you don't anticipate changing any of the core code, this is probably the easier option.

Note that for both options you need to build OpenSpiel from source.

Hope this helps!

Got it, if anyone has the same problem, read about environment variables in Ubuntu.
I put the path before the open_spiel folder in ${path_to_open} and it worked.