Skip to content

Using Spcppl Library

poikniok edited this page Nov 22, 2019 · 9 revisions

This page assumes that the steps on the Simplest Configuration Using Default Project wiki page have been completed. Following these next steps will allow Clion to automatically import from the spcppl library, and include the code in the output/main.cpp for submission.

With the example project now open:

  • Go the spcppl github page and download the zip file.
  • Move the spcppl folder that you have now downloaded under the jhelper-example-project directory.
  • Go to the CMakeLists.txt that is under the jhelper-example-project (NOT the one in the spcppl directory). The last line of it should be add_executable(test ${TASKS} ${HEADERS}). After the last line, at the very end of this file (this is important), add the following 4 lines
add_subdirectory(spcppl)  
target_link_libraries(testrunner spcppl)  
target_link_libraries(output spcppl)  
target_link_libraries(test spcppl)
  • Clion should prompt you to now refresh the CMakeLists.txt, if you do not have auto-refresh configured. If it does not prompt you, and you are not absolutely certain you have auto-refresh configured go to File - Reload Cmake Project. Doing this is absolutely critical, if Clion is using the old Cmake, the importing of the library will not work!
  • Now test your usage of the library out. Add the following code block in your "Task.cpp":
for (int i : range(10)) {
  out << i << std::endl;
}

Clion will not immediately recognize what this range function is, and thus will underline it in red. Press Option+Return (on mac) or Alt+Return (on linux) with the cursor over the "range" to import it. The import should now show up at the top of your "Task.cpp", and when you now run your task you will see the numbers 0-9 printed!

  • Now in your project, you can go to the output/main.cpp and see that the generated code (which is what you will be submitting) has included the library! You should also see that the #ifndef SPCPPL_ASSERT block will show up there, this is important, as it verifies that the imports used by the spcppl library are being correctly added to the generated code as well.

Important Note for Mac Users: If you include the line using namespace std; in your Task / Task.template etc, auto-import will not work if you are using Mac! It will however work if you are using Linux (for me), and will also work if using Window (for Egor). So if you are using Mac, and auto-import for the library is not working, make sure you have not set using namespace std!