Use cmake on Linux to create the CodeBlocks project, cmakecodeblocks

Source: Internet
Author: User

Use cmake on Linux to create the CodeBlocks project, cmakecodeblocks

Recently, cmake has been used in linux, and it is really difficult to adapt to the use of GUI. I am trying my best to create the project that used cmake as a CodeBlocks project. The project is acceptable when it is small, and it is too much trouble.

After reading the official cmake documentation, you can use commands to generate the codeblocks project in Versions later than 2.2.8... however, there are not many related articles, and there may not be too many things I think about. Generally, CMake is a master and won't be so cool, let's start with the simplest project.

Because the cmake official Recommendation uses external compilation, we 'd better use external compilation. Create a folder named t1, and create two directories, Hello_src and build, respectively. Hello_src stores the source file and cmakelists.txt, and build the generated codeblocks project.

  

The main. c code is

1 #include <stdio.h>2 int main()3 {4     printf("Hello World from t1 Main!\n");5     return 0;6 }

CMakeLists.txt

1 PROJECT (HELLO)2 SET(SRC_LIST main.c)3 MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})4 MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})5 ADD_EXECUTABLE(hello  ${SRC_LIST})

Cmake ../Hello_src-G "CodeBlocks-Unix Makefiles"

Go to build and you will see the codeblocks project.

However, there is a problem with directly compiling and running,

Select project-> properties-> Build targets

Change

 

Then click compile to run successfully:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.