How do I debug a binary that is not built with CLion?

I'm pretty new to CLIon, but have been using IntelliJ for years.

I'm playing around with CLion to try some work on an open source project that I don't control (and they don't use CMake).  I can point CLion at the directory structure and get pretty reasonable browsing, but when I go to the debug configurations drop down (where i would setup IntellJ to launch a Java class), I can only select targets that CLion knows about.  What I would like to be able to do is point to a binary on the file system to run and debug.

Am I missing something obvious in the UI?
If this is not implemented, are there any CMake tricks I can do to have it point to an existing file?

Thanks!

4 comments
Avatar
Alexander Kirillin
Comment actions Permalink

Will, you have to add a target to CMakeLists.txt to run it.
Here is an example of CMakeLists.txt file:

project(BasicProject)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libstdc++")
add_executable(Target test.cpp)
0
Comment actions Permalink

Does this mean my only choice is to port ths build scripts for the open source project to CMake?  The CMake snippet you added, seemed to be the same you would use for building a target from test.cpp, rather than pointing to an already built binary.

Clearly, for a lot of projects doing port of the build system can be significant.  I can already use their existing build, I'd just like to be able to debug against their binaries.  Is that not possible?

0
Avatar
Alexander Kirillin
Comment actions Permalink

Yes, it's possible to point to an already built executble - see http://www.cmake.org/cmake/help/v3.0/command/add_executable.html for reference.

0
Comment actions Permalink

I can't get this to work.  I can get CMake to seem to accept it just fine, but when I try to set the target to debug, it is not including ninja_test.

I added:

  SET( EXTERNAL_EXE "/Users/wpugh/projects/ninja/ninja_test" )

 
 SET( IMPORTED_LOCATION ${EXTERNAL_EXE} )
ADD_EXECUTABLE( ${EXTERNAL_EXE} IMPORTED)
set_target_properties(${EXTERNAL_EXE} PROPERTIES IMPORTED_LOCATION "/Users/wpugh/projects/ninja/ninja_test")


I've also tried naming the new executable ninja_test.  Nothing seems to work.

Is there anyone out there that has gotten this to work?  Am I getting confused on the CMake part of it?

0

Please sign in to leave a comment.