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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:38:51+00:00 2026-05-31T06:38:51+00:00

The project I’m compiling uses CMake, which loves absolute pathnames . When I compile

  • 0

The project I’m compiling uses CMake, which loves absolute pathnames.

When I compile with debugging information enabled, gcc puts those long names into .debug_str sections, which is bad for debugging. I’d like to have short relative-to-project-root pathnames there instead.

Is there some option to tell gcc to strip some part of pathname before emitting debug data? Or, maybe, there is some tool that could do that on compiled binaries?

I’ve tried using SET(CMAKE_USE_RELATIVE_PATHS ON) (which seems to be frowned upon by devs) option, but as I’m using out-of-source builds, pathnames are still not in the form I’d want them to be. I.e. they’re ./../src/mod_foo/foo.c instead of mod_foo/foo.c.

  • 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-31T06:38:52+00:00Added an answer on May 31, 2026 at 6:38 am

    You can set the RULE_LAUNCH_COMPILE property of a CMake target to have CMake invoke a shell script which transforms the source file path to a project relative path before invoking gcc. Use the CMake function configure_file to generate a shell script which knows about the PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR of your project.

    In your outermost CMakeLists.txt add the following code:

    configure_file(
        "${PROJECT_SOURCE_DIR}/gcc_debug_fix.sh.in"
        "${PROJECT_BINARY_DIR}/gcc_debug_fix.sh"
        @ONLY)
    
    add_executable (MyExecutable ...)
    
    set_target_properties(MyExecutable PROPERTIES 
        RULE_LAUNCH_COMPILE "${PROJECT_BINARY_DIR}/gcc_debug_fix.sh")
    

    The following template shell script gcc_debug_fix.sh.in needs to go to the root directory of the CMake project:

    #!/bin/sh
    
    PROJECT_BINARY_DIR="@PROJECT_BINARY_DIR@"
    PROJECT_SOURCE_DIR="@PROJECT_SOURCE_DIR@"
    
    # shell script invoked with the following arguments
    # $(CXX) $(CXX_DEFINES) $(CXX_FLAGS) -o OBJECT_FILE -c SOURCE_FILE
    
    # extract parameters
    SOURCE_FILE="${@: -1:1}"
    OBJECT_FILE="${@: -3:1}"
    COMPILER_AND_FLAGS=${@:1:$#-4}
    
    # make source file path relative to project source dir
    SOURCE_FILE_RELATIVE="${SOURCE_FILE:${#PROJECT_SOURCE_DIR} + 1}"
    
    # make object file path absolute
    OBJECT_FILE_ABSOLUTE="$PROJECT_BINARY_DIR/$OBJECT_FILE"
    
    cd "$PROJECT_SOURCE_DIR"
    
    # invoke compiler
    exec $COMPILER_AND_FLAGS -c "${SOURCE_FILE_RELATIVE}" -o "${OBJECT_FILE_ABSOLUTE}"
    

    The shell script uses the information from the variables PROJECT_BINARY_DIR and PROJECT_SOURCE_DIR to transform the path of the source file to a path relative to the project root and the object file’s path to an absolute path. Because gcc gets passed a project relative path now, .debug_str should use that path, too.

    The following caveats apply:

    • Be sure to set the executable bit of gcc_debug_fix.sh.in.
    • For the script to work CMAKE_USE_RELATIVE_PATHS has to set to OFF again.
    • The script makes assumptions about the location of the file paths on the command line. This may not work if CMake uses a different rule to invoke the compiler. A more robust solution would be to scan the script arguments for the -o and -c flags.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My project is currently using a svn repository which gains several hundred new revisions
Project I'm working on uses jQuery. I have a series of Ajax calls being
Project Description: I have to make an application in android which gets the Latitude
Our project uses XJC to generate Java classes from an XSD. I'm using JAVA
Project: ASP.NET 3.5 with C# I have this much :- A table which used
My Project have two Screen in which Activity A and Activity B. Activity A
My project uses both NServiceBus and RavenDB. NServiceBus uses log4Net, and RavenDB uses NLog.
Project Darkstar was the topic of the monthly JavaSIG meeting down at the Google
Project: http://design.vitalbmx.com/fave/news.html When I click Add to favorites button (under main pic), in Chrome
Project layout: /project_a /shared /project_b /shared /shared project_a and project_b both need to contain

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.