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 581885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:37:40+00:00 2026-05-13T14:37:40+00:00

gcc 4.4.2 cmake 2.6 I have just started using cmake. Coming from writing my

  • 0

gcc 4.4.2
cmake 2.6

I have just started using cmake. Coming from writing my own Makefiles.

However, I have this directory structure and using out-of-source build. To separate the source files from the build files.

project
    src
        my_c_files.c
        CMakeLists.txt
    build
        Makefile

Before I would write my own Makefiles in the src directory and then press F5 and I was able to compile my program. And emacs would list any warning or errors. However, it seems that I have to open a terminal and go to the build directory to run

cmake ../src

and then

make

I would like to run make from within emacs the same as pressing F5. But as the Makefile as been generated in the build directory, and emacs is looking for it in the src directory.

Even when I set a soft link to the Makefile in the src directory to link to the Makefile in the build directory. All this did was give me a list of errors.

  • 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-13T14:37:40+00:00Added an answer on May 13, 2026 at 2:37 pm

    For exactly the same purpose I found .dir-locals.el to be extremely helpful, here’s how one of mine looks like:

    ((nil . ((tab-width . 8)
         (indent-tabs-mode . t)))
     (c++-mode . ((c-basic-offset . 8)
              (tab-width . 8)
              (indent-tabs-mode . t)
              (compile-command . "make -C ../build -j 2 run_tests")))
     ((c-mode . ((c-basic-offset . 8)
             (tab-width . 8)
             (indent-tabs-mode . t)
             (compile-command . "make -C ../build -j 2 run_tests")))))
    

    Obviously I can have paths specified in different .dir_locals.el according to their location and such, say some build run_tests for unit test, some build the real target and so on.

    Then I put a dummy makefile in the build directory, which looks like this:

    all: run_tests
    
    run_tests:
        @cmake ..
        @make -j 2
    

    This way I can make a checkout and just run M-x compile in whichever file I like and it will do the right thing. I use git and have that Makefile ignored from monitoring by git like so:

    git update-index --assume-unchanged Makefile

    and if I want to modify and commit it I do

    git update-index --no-assume-unchanged Makefile.

    This way the newly created by cmake Makefile won’t show in git status as modified, and I won’t commit it accidentally.

    Benefits of this approach:

    • since cmake uses absolute paths internally, there’s absolutely no problem jumping through compilation errors in compilation buffer by just pressing enter on them.

    • you can specify whatever indentation rules you want there, and they can be different in different projects or even directories if you so please 🙂

    • you can specify any amount of targets you want in different projects, even directories, still use the same old M-x compile (I have it bound to C-c b) and get Emacs to do the right thing.

    The only drawback there is having .dir-locals.el in your subdirectories, which I hardly find bad.

    EDIT: robUK, to answer your comment:

    Here is documentation for Per-Directory Local Variables as they call it in Emacs manual. It is not a package, it’s a part of Emacs, although I’m not sure if it was available in pre-23 versions, I’m using 23.1.1.

    EDIT2: liwp, to answer your question:

    As Charles already pointed out, and as documentation says:

    If you put a file with a special name
    .dir-locals.el in a directory, Emacs
    will read it when it visits any file
    in that directory or any of its
    subdirectories, and apply the settings
    it specifies to the file’s buffer.
    Emacs searches for .dir-locals.el
    starting in the directory of the
    visited file, and moving up the
    directory tree. (To avoid slowdown,
    this search is skipped for remote
    files.)

    You don’t need .dir-locals.el everywhere in your project tree. Note, however, it probably depends on the complexity of your code base structure.

    I normally would go for a fairly simple layout like this:

    /project_root_dir
        /build
        /src
        /test
    

    and I would have slightly different targets specified in different .dir-locals.el, say in /test I would only build testrunner and have it executed, I’d spend most of the development time building this target. Then in /src I would first build the same testrunner, have it executed,and if everything goes well there, it would build me my main project target. If you don’t need this, you could be fine with just one .dir-locals.el under /project_root_dir. If your source structure and requirements are a lot more sophisticated, it could mean you’d need a bit more path- and target-related wizardry.

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

Sidebar

Related Questions

gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,
I have a number of projects built using CMake and I'd like to be
I'm using cmake with C++ project. I want to use precompiled headers in GCC.
GCC 4.6.0 Linux cmake 2.8 I am using cmake to generate my make file.
I have begun using the waf build system as an alternative to CMake. So
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
GCC is a very well respected multi-language compiler (from what I've gathered). One thing
gcc I am just getting back into c programming and I am just practicing
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,

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.