Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:05:39+00:00 2026-05-26T05:05:39+00:00

In a GCC compiled project, How do I run CMake for each target type

  • 0

In a GCC compiled project,

  • How do I run CMake for each target type (debug/release)?
  • How do I specify debug and release C/C++ flags using CMake?
  • How do I express that the main executable will be compiled with g++ and one nested library with gcc?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:05:39+00:00Added an answer on May 26, 2026 at 5:05 am

    With CMake, it’s generally recommended to do an “out of source” build. Create your CMakeLists.txt in the root of your project. Then from the root of your project:

    mkdir Release
    cd Release
    cmake -DCMAKE_BUILD_TYPE=Release ..
    make
    

    And for Debug (again from the root of your project):

    mkdir Debug
    cd Debug
    cmake -DCMAKE_BUILD_TYPE=Debug ..
    make
    

    Release / Debug will add the appropriate flags for your compiler. There are also RelWithDebInfo and MinSizeRel build configurations.


    You can modify/add to the flags by specifying a toolchain file in which you can add CMAKE_<LANG>_FLAGS_<CONFIG>_INIT variables, e.g.:

    set(CMAKE_CXX_FLAGS_DEBUG_INIT "-Wall")
    set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wall")
    

    See CMAKE_BUILD_TYPE for more details.


    As for your third question, I’m not sure what you are asking exactly. CMake should automatically detect and use the compiler appropriate for your different source files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code compiled by gcc: #include <iostream> using namespace std; class
I know that c++ code should be compiled and linked by g++, not gcc.
I am using Eclipse CDT with Cygwin GCC 3 as compiler. My project is
We are running some code on a project that uses OpenMP and I've run
I'm working on a large collaborative C++ project that is both developed and run
gcc 4.4.2 cmake 2.6 I have just started using cmake. Coming from writing my
I'm developing cross-platform project that would support : Four C++ compilers - GCC, MSVC,
I'm trying to make my project compile under GCC (Visual Studio compiles it flawlessly).
Say we want to compile a large project (say GCC or the Linux kernel)
Under gcc (g++), I have compiled a static .a (call it some_static_lib.a ) library.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.