To learn more about various build actions available in CLion, see Build actions. So we can use this configuration not only to debug or run our target but also to perform the build. Notice the Before launch area of this dialog: Build is set as a before launch step by default. The target name and the executable name were taken directly from the CMakeLists.txt: Upon the first project loading, CLion automatically adds a Run/Debug configuration associated with this target:Ĭlick Edit Configurations in the switcher or select Run | Edit Configurations from the main menu to view the details. You can define multiple build targets in a single script.įor now, our test project has only one build target, cmake_testapp. Target is an executable or a library to be built using a CMake script. Build targets and Run/Debug configurations Sets the CMAKE_CXX_STANDARD variable to the value of 14, as we selected when creating the project.Īdds the cmake_testapp executable target which will be built from main.cpp.Ģ. It is set to the version of CMake bundled in CLion (always one of the newest versions available).ĭefines the project name according to what we provided during project creation. Helloworld: $ cd helloworld $ touch makefile $ vi makefile # create the makefile as below $ make g++ -o hello helloworld.Specifies the minimum required version of CMake. That’s why GNU also provides an automation tool - GNU Make.Ī simple makefile consists of rules with the following syntax: target. ![]() With large C++ projects - which can involve thousands of separate files, including source files, object files, libraries, and executables - building from the command line is a hard task. phone The list software: Gmail GoogleMap The list hardware Camera Screen Building C++ App by makefile dynamiclib/libsoftware.dylib # remember copy dynamic library to executable file or install in in directory where the system can read it. ![]() dynamiclib/include # linking the application with static and dynamic library $ g++ -o phone phone.o -L./staticlib -L./dynamiclib -lhardware -lsoftware Or $ g++ -o phone phone.o. Static library: $ cd staticlib # Compile source file to object without linking # -c: Only run preprocess, compile, and assemble steps (without linking) # -I: Add directory to include search path $ g++ -c -o camera.o src/camera.cpp -I include/hardware $ g++ -c -o screen.o src/screen.cpp -I include/hardware $ g++ -c -o hardware.o src/hardware.cpp -I include/hardware # Link the object files into a static library $ ar ru libhardware.a screen.o camera.o hardware.o $ ranlib libhardware.aĭynamic library: $ cd dynamiclib # Compile source file to object without linking $ g++ -c -o gmail.o src/gmail.cpp -I include/software $ g++ -c -o googlemap.o src/googlemap.cpp -I include/software $ g++ -c -o software.o src/software.cpp -I include/software # create dynamic library $ g++ -shared -fPIC -o libsoftware.dylib gmail.o googlemap.o software.oĪn executable: $ cd phone # Compile source file to object without linking $ g++ -c -o phone.o phone.cpp -I. Simple! right? Now let’s try a more complex application including static library and dynamic library: ![]() Helloworld: Let’s start with helloworld example: $ cd helloworld # -o : output file $ g++ -o hello helloworld.cpp $ ls hello helloworld.cpp $. ├── helloworld │ └── helloworld.cpp ├── phone │ └── phone.cpp ├── dynamiclib │ ├── include │ │ └── software │ │ ├── gmail.hpp │ │ ├── googlemap.hpp │ │ └── software.hpp │ └── src │ ├── gmail.cpp │ ├── googlemap.cpp │ └── software.cpp └── staticlib ├── include │ └── hardware │ ├── camera.hpp │ ├── hardware.hpp │ └── screen.hpp └── src ├── camera.cpp ├── hardware.cpp └── screen.cpp Building C++ App by Command Line To understand the build process, I’ve made a project which has four modules: a simple executable helloworld, a static library, a dynamic library, and an executable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |