microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 451 forks source link

can not launch ? #617

Closed narutojxl closed 5 years ago

narutojxl commented 5 years ago

My VS Code version="1.30.1", ubuntu 14.04, when type cmake --version, its output is "cmake version 3.5.1" , g++ --version ="g++ (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4". I also install some VS Code extension, C/C++ 0.20.1, CMake 0.0.17, CMake Tools 1.1.3. I can build c++ project successfully, but when i launch vscode, nothing output as if the executable not running, but in terminator, i can run the code. There is a screenshot of vscode after launch, something missing?? Thank you very much!

build result: [build] Starting build [proc] Executing command: /usr/bin/cmake --build /home/jxl/projects/test1/build --config Debug --target all -- -j 6 [build] [1/1 100% :: 0.000] Re-running CMake... [build] -- Using CATKIN_DEVEL_PREFIX: /home/jxl/projects/test1/build/devel [build] -- Using CMAKE_PREFIX_PATH: /home/jxl/carto_ws/install_isolated;/home/jxl/jxl_ws/devel;/opt/ros/indigo [build] -- This workspace overlays: /home/jxl/carto_ws/install_isolated;/home/jxl/jxl_ws/devel;/opt/ros/indigo [build] -- Using PYTHON_EXECUTABLE: /usr/bin/python [build] -- Using Debian Python package layout [build] -- Using empy: /usr/bin/empy [build] -- Using CATKIN_ENABLE_TESTING: ON [build] -- Call enable_testing() [build] -- Using CATKIN_TEST_RESULTS_DIR: /home/jxl/projects/test1/build/test_results [build] -- Found gtest sources under '/usr/src/gtest': gtests will be built [build] -- Using Python nosetests: /usr/bin/nosetests-2.7 [build] -- catkin 0.6.19 [build] -- Boost version: 1.54.0 [build] -- Configuring done [build] -- Generating done [build] -- Build files have been written to: /home/jxl/projects/test1/build [build] [1/2 50% :: 0.000] Building CXX object CMakeFiles/test1.dir/src/main.cpp.o [build] [2/2 100% :: 0.219] Linking CXX executable devel/lib/test1/test1 [build] Build finished with exit code 0

launch.json: { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "/home/jxl/projects/test1/build/devel/lib/test1/test1", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }

KoeMai commented 5 years ago

Did you try the executable from commandline? Or by gdb on commandline? The cmake Tools does not use launch.json to start debugging. The Support for debugging with cmake Tools should work with cmake >3.7.1.

narutojxl commented 5 years ago

Yes, i can run the executable from commandline. But when i "start without debugging", there is nothing output. Yes, you are right, only with cmake >3.7.2, according to Target Debugging and Launching, we can debug. I want to firstly to make the simple C++ project can run successfully with vscode.

-I have upgrade my gcc and g++ from 4.8.4 to 7.4 according to Install_gcc7_ubuntu_16.04.md,

jxl@lenovo:/usr/bin$ g++ --version g++ (Ubuntu 7.4.0-1ubuntu114.04ppa1) 7.4.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. jxl@lenovo:/usr/bin$ jxl@lenovo:/usr/bin$ jxl@lenovo:/usr/bin$ gcc --version gcc (Ubuntu 7.4.0-1ubuntu114.04ppa1) 7.4.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. jxl@lenovo:/usr/bin$ ls g++ g++ g++-4.8 g++-7 jxl@lenovo:/usr/bin$ jxl@lenovo:/usr/bin$ jxl@lenovo:/usr/bin$ ls gcc gcc gcc-4.8 gcc-7 gcc-ar gcc-ar-4.8 gcc-ar-7 gcc-nm gcc-nm-4.8 gcc-nm-7 gcc-ranlib gcc-ranlib-4.8 gcc-ranlib-7 jxl@lenovo:/usr/bin$

-But when clean and rebuild in vscode, it still use g++-4.8, there is not g++-7 or gcc-7 in choosed kits.

[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-4.8 -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-4.8 -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release -H/home/jxl/projects/test1 -B/home/jxl/projects/test1/build -GNinja [cmake] Not searching for unused variables given on the command line. [cmake] -- Using CATKIN_DEVEL_PREFIX: /home/jxl/projects/test1/build/devel [cmake] -- Using CMAKE_PREFIX_PATH: /home/jxl/carto_ws/install_isolated;/home/jxl/jxl_ws/devel;/opt/ros/indigo [cmake] -- This workspace overlays: /home/jxl/carto_ws/install_isolated;/home/jxl/jxl_ws/devel;/opt/ros/indigo [cmake] -- Using PYTHON_EXECUTABLE: /usr/bin/python [cmake] -- Using Debian Python package layout [cmake] -- Using empy: /usr/bin/empy [cmake] -- Using CATKIN_ENABLE_TESTING: ON [cmake] -- Call enable_testing() [cmake] -- Using CATKIN_TEST_RESULTS_DIR: /home/jxl/projects/test1/build/test_results [cmake] -- Found gtest sources under '/usr/src/gtest': gtests will be built [cmake] -- Using Python nosetests: /usr/bin/nosetests-2.7 [cmake] -- catkin 0.6.19 [cmake] -- Boost version: 1.54.0 [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: /home/jxl/projects/test1/build [build] Starting build [proc] Executing command: /usr/bin/cmake --build /home/jxl/projects/test1/build --config Release --target all -- -j 6 [build] [1/2 50% :: 0.000] Building CXX object CMakeFiles/test1.dir/src/main.cpp.o [build] [2/2 100% :: 0.382] Linking CXX executable devel/lib/test1/test1 [build] Build finished with exit code 0

narutojxl commented 5 years ago

I solved this problem following these steps:

  1. choose CMake type: Debug.

  2. set cmake.cmakePath in user settings or in workspace settings with cmake > 3.7.2, for example:"cmake.cmakePath": "/home/jxl/cmake-3.13.1/INSTALL_JXL/bin/cmake",

  3. build the project.

  4. setting executable path in launch.json, "request": "launch", not "attach". for example.

"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "/home/jxl/projects/test1/build/devel/lib/test1/test1",

  1. set breakpoints and start debug with ctrl + F5, not use vscode toolbar's Debug--->Start Debugging(F5), it doesn't work.
  1. set CMake type: release or debug.

  2. Build project with any cmake version.

  3. setting launch.json.

  4. run executable with shift + F5, not use vscode toolbar's Start without Debugging, it doesn't work.