Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear example for compiling example programs #815

Closed
alexklibisz opened this issue Nov 23, 2016 · 5 comments
Closed

Clear example for compiling example programs #815

alexklibisz opened this issue Nov 23, 2016 · 5 comments

Comments

@alexklibisz
Copy link

I apologize if I'm overlooking something. Is there an example somewhere for compiling the programs on this page: http://www.mlpack.org/docs/mlpack-git/doxygen.php?doc=sample.html

Maybe this is obvious to some, but I've been digging through issues and google for an hour now trying to get the second program to compile and run on Ubuntu 16.04. It would be great if the necessary g++ commands or a makefile were made available.

Thanks

@alexklibisz
Copy link
Author

I was able to get it working on ubuntu by installing

sudo apt-get install libmlpack-dev libboost-all-dev

and compiled using

g++ nnserach.cpp -std=c++11 -lboost_serialization -larmadillo -lmlpack

and switching the Log statements to cout.

@rcurtin
Copy link
Member

rcurtin commented Nov 23, 2016

Hi Alex,

Sorry that you had trouble. One of the reasons that we don't give the GCC commands or a Makefile is because the particular command we give might not work for every Linux distribution or environment that a user might be on, and that could result in more confusion.

I see that the way that the sample program is written, no output will actually be given (because by default Log::Info doesn't print anything). I've changed the example to cout in a1dafa4.

Feel free to file more issues if you have any more problems.

Thanks,
Ryan

@mas-dse-greina
Copy link

I followed Alex's apt-get commands and it seemed to install for me on Ubuntu 16.04.

I took the example file and tried to compile it just like Alex compiled nnserach.cpp:

// Includes all relevant components of mlpack. #include <mlpack/core.hpp> // Convenience. using namespace mlpack; int main() { // First, load the data. arma::mat data; // Use data::Load() which transposes the matrix. data::Load("data.csv", data, true); // Now compute the covariance. We assume that the data is already centered. // Remember, because the matrix is column-major, the covariance operation is // transposed. arma::mat cov = data * trans(data) / data.n_cols; // Save the output. data::Save("cov.csv", cov, true); }

However, it is giving me lots of errors about not finding declarations:
gcc mlpackTest.cpp -o mlOutTest -lboost_serialization -larmadillo -lmlpack In file included from /usr/include/c++/5/unordered_map:35:0, from /usr/include/mlpack/core/boost_backport/unordered_map.hpp:23, from /usr/include/mlpack/prereqs.hpp:64, from /usr/include/mlpack/core.hpp:196, from mlpackTest.cpp:2: /usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support \ ^ In file included from /usr/include/mlpack/prereqs.hpp:64:0, from /usr/include/mlpack/core.hpp:196, from mlpackTest.cpp:2: /usr/include/mlpack/core/boost_backport/unordered_map.hpp:98:16: error: ‘unordered_map’ in namespace ‘std’ does not name a template type const std::unordered_map< ^ /usr/include/mlpack/core/boost_backport/unordered_map.hpp:98:29: error: expected ‘,’ or ‘...’ before ‘<’ token const std::unordered_map< ^ /usr/include/mlpack/core/boost_backport/unordered_map.hpp: In function ‘void boost::serialization::save(Archive&, int)’: /usr/include/mlpack/core/boost_backport/unordered_map.hpp:105:9: error: ‘unordered_map’ is not a member of ‘std’ std::unordered_map< ^ /usr/include/mlpack/core/boost_backport/unordered_map.hpp:105:9: error: ‘unordered_map’ is not a member of ‘std’

It seems to be finding the includes, but I have no clue as to what other compile and link flags I need to get things built.

What IDE do you guys use to build projects on Linux? Or, do you just use text editors and CMake.

Thanks.
-Tony

@rcurtin
Copy link
Member

rcurtin commented Dec 21, 2016

Hi Tony,

You need to add the -std=c++11 flag to your gcc call. :) "This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options." I added a little bit to the tutorial in 20da685 so that should help clarify the need for a C++11 compiler.

Personally I don't use an IDE to develop mlpack, just vim + GNU screen + command-line. I am sure some others do use IDEs but I have never set one up for my own use.

I hope this is helpful. Let me know if there is anything else I can clarify.

Thanks,
Ryan

@mas-dse-greina
Copy link

g++ -std=c++11 mlpackTest.cpp -o MLTEST -larmadillo -lmlpack -lboost_serialization

That worked. Thanks so much.

-Tony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants