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

Create a tutorial for using the C API in a C/C++ application #6174

Open
hcho3 opened this issue Sep 27, 2020 · 6 comments
Open

Create a tutorial for using the C API in a C/C++ application #6174

hcho3 opened this issue Sep 27, 2020 · 6 comments

Comments

@hcho3
Copy link
Collaborator

@hcho3 hcho3 commented Sep 27, 2020

It would be great to have a tutorial for using the C API of XGBoost in a C or C++ application. Some important components:

  • How to configure the CMakeLists.txt of your application to link with XGBoost (either statically or dynamically)
  • How to install XGBoost library into a system prefix or a Conda environment.
  • Useful tips, such as remembering to clean up allocated XGBoost object handles, or exception handling with XGBGetLastError().
  • Link to the demo: https://github.com/dmlc/xgboost/blob/master/demo/c-api/c-api-demo.c

Note to new contributors: Post a comment here if you'd like to work on this issue. Feel free to ping me for help.

@divya661
Copy link
Contributor

@divya661 divya661 commented Sep 27, 2020

@hcho3 hello, sir
I'm efficient in C++ and would like to work on this? I will update you as soon as possible. How I can connect with you for help & guidance( like slack/discord/discourse/ or the discussion forum of XGBoost)? I've read the contributing guidelines & coding guidlines in C++ provided in the XGBoost documentation. Could you please assign it to me? I've started working on it.

@hcho3
Copy link
Collaborator Author

@hcho3 hcho3 commented Sep 27, 2020

@divya661 Thanks for volunteering. You have two options:

@divya661
Copy link
Contributor

@divya661 divya661 commented Oct 1, 2020

@hcho3 Sir, could you please suggest me a few resources regarding the first 2 points of this issue?

@hcho3
Copy link
Collaborator Author

@hcho3 hcho3 commented Oct 1, 2020

@divya661 Take a look at

- name: Build and install XGBoost
shell: bash -l {0}
run: |
mkdir build
cd build
cmake .. -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -GNinja
ninja -v install
- name: Build and run C API demo
shell: bash -l {0}
run: |
cd demo/c-api/
mkdir build
cd build
cmake .. -GNinja -DCMAKE_PREFIX_PATH=$CONDA_PREFIX
ninja -v
cd ..
./build/api-demo
, which is an automated script to test the C API example (https://github.com/dmlc/xgboost/blob/master/demo/c-api/c-api-demo.c).

@divya661
Copy link
Contributor

@divya661 divya661 commented Oct 6, 2020

@hcho3 in point 2, by "system prefix" you mean with different OS like Windows, Mac OS & others? (want to confirm)

@hcho3
Copy link
Collaborator Author

@hcho3 hcho3 commented Oct 6, 2020

@divya661 No, the prefix refers to a directory where a package is to be installed. The term is used in GNU Autotools, e.g. https://www.gnu.org/prep/standards/html_node/Directory-Variables.html. The system prefix on Linux is /usr/local. It's called "system" prefix because the prefix is set system-wide.

Since writing to /usr/local requires the administrative privilege, it is often convenient to install a package into another prefix directory that is different from the system prefix (/usr/local). Creating a Conda environment creates a new prefix directory inside the user's home directory (usually $HOME/miniconda3/envs/[env_name]). Since this prefix is inside the home directory, the user is able to install packages into it without needing a permission from the administrator.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.