I'm using Visual Studio Code on Ubuntu 18.04 to write some C++ code using external libraries. I'm not sure why, but whenever I run the debugger, the contents of most variables doesn't show.
I've attached an example of this issue.
Why is this happening?
Edit:
cmake_minimum_required(VERSION 3.10.2)
project(Proj)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
set(ARENA_DIR "~/Arena")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CC "g++")
set(CFLAGS "-Wall -g -O2 -std=c++14 -Wno-unknown-pragmas")
add_definitions(${CFLAGS})
set(RM "rm -f")
include_directories(${ARENA_DIR}include/Arena)
include_directories(${ARENA_DIR}include/GenTL)
include_directories(${ARENA_DIR}include/Save)
include_directories(${ARENA_DIR}GenICam/library/CPP/include)
...
set(ARENA_DEBUG_LIBS
${ARENA_DIR}libarenad.so
${ARENA_DIR}libsaved.so
${ARENA_DIR}libgentld.so)
set(ARENA_RELEASE_LIBS
${ARENA_DIR}libarena.so
${ARENA_DIR}libsave.so
${ARENA_DIR}libgentl.so)
set(LIBS
${GENICAMLIBS}
${FFMPEGLIBS}
"/usr/lib/x86_64-linux-gnu/libpthread.so")
add_executable(main main.cpp)
set_target_properties(main PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
target_link_libraries(main ${LIBS} debug ${ARENA_DEBUG_LIBS})
target_link_libraries(main ${LIBS} optimized ${ARENA_RELEASE_LIBS})
Edit 2:
After changing the g++ flag to -O0 instead of -O2, I get this result:
But I would expect to be able to see the object's properties.
Related
When starting a new C++ project on VSCode with CMake Tools extension, we can run the "Cmake: quick start" command to generate a basic CMakeLists.txt file with basic project configuration. I would like to know if i can customize this generation so it includes some additional configuration on every new project. I like to use address sanitizer on even simple programs i create so i want to have it setup automatically.
Standard config:
cmake_minimum_required(VERSION 3.0.0)
project(filas VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(filas main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
The additional config i want:
if(CMAKE_DEFAULT_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fsanitize=undefined -fsanitize=address")
target_link_options(filas
BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address
)
endif()
I'm a beginner at C++ and CMake and couldn't find this specific info so far.
I want to implement a Matrix class, and I want to use CUDA to speed up matrix multiplication. But when I try to compile the source files. I meet some problems. I know that I need to use NVCC to compile the *.cu. But I don't know how to write the CMakeLists.txt to compile the *.cu and *.cpp at the same time. I've tried many ways I found on Google, but they all don't work. Here is my current CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(Project_4 LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
find_package(CUDA REQUIRED)
include(FindCUDA)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)
include_directories(include)
aux_source_directory(src DIR_SRCS)
file(GLOB cu *.cu)
cuda_add_executable(cuda ${DIR_SRCS} ${cu})
add_executable(Project_4 ${DIR_SRCS})
set_target_properties(Project_4 PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
Then when compiling, it will report that CMake Error at cuda_generated_ cuda_helper.cu.o.RELEASE.cmake:282. And if I write CMakeLists.txt in this way:
cmake_minimum_required(VERSION 3.16)
project(Project_4 LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
include_directories(include)
aux_source_directory(src DIR_SRCS)
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)
add_executable(Project_4 ${DIR_SRCS})
set_target_properties(Project_4 PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
Then it will report error error: expected primary-expression before "<" token at where I call the kernel function.
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this. I will appreciate a lot. Thanks.
I created an example for you. It is not based on your cmake. But it works for me maybe it helps you.
clone repo: git clone -b cmake_cuda_example https://github.com/werto87/durak_computer_controlled_opponent.git
install: conan dependency manager
Install: cuda toolkit
create an empty folder called build inside the "durak_computer_controlled_opponent" folder
go inside this folder and inside the terminal run "conan install .. --build missing"
cmake ..
cmake --build .
I have a big C++ program in VS code under Ubuntu 18.4, I am using CMake. I need to Know what areas are spending more time and memory space. I am a beginner in coding in Linux and using CMakeLists.txt files. I tried to use gprof, I added
if(MSVC AND MT)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()
to my CMakeLists.txt file. Then I complied the program using cmake .. and then make, after that I run the program with an example, and when using the command gprof ./myexe I get gmon.out: No such file or directory
I am using a WSL running Ubuntu and am trying to get an SDL2 program to compile using the Ubuntu and then run the program on Windows. I have been able to get it to build, however it doesn't make an exe (and changing the file extension to exe doesn't fix it). Also even though I set the CMAKE_CXX_FLAGS to have -o Crawl_The_Dungeon.exe the file still ends up being named all lower case like the project name. I was able to get this to compile and run on linux when I still had a linux machine.
I am still pretty new to CMake so I don't fully understand if I am close at all or not at all.
SET(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CXX_STANDARD 14) # Enable c++14 standard
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${crawl_the_dungeon_SOURCE_DIR}/CMakePath")
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
project(crawl_the_dungeon)
set(SOURCE_FILES final.cpp Soldier.cpp TilesEnum.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --static -std=c++0x")
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIR})
target_link_libraries(crawl_the_dungeon ${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
EDIT: I was dumb to include -o Crawl_The_Dungeon.exe as it now creates an exe. However it says that I can't run the program when opening it.
I want to create a CMakeLists that outputs two versions of my executable. One is going to be a release version of my C app.
The other is the gtest version of my app.
cmake_minimum_required(VERSION 3.1)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "C:\\Users\\James\\ClionProjects\\DustAgent\\build")
project(DustAgent)
include_directories ( WindowsApi gtest-1.7.0/include )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -pthread")
set(SOURCE_FILES main.c utilities/utilities.c utf8/utf8.c)
set(GTEST_SOURCE_FILES ${SOURCE_FILES} gtest-1.7.0/src/gtest-all.cc)
add_executable(DustAgent ${SOURCE_FILES})
How do I make it so that the first exe doesn't require the google library and how do I give specific gcc options for c++ to the gtest version?
you should create a library first and then link both, the executable and the test, with it. The executable and the test should have a separate source code though.
add_library(DustAgentLibrary utilities/utilities.c utf8/utf8.c)
add_executable(DustAgent main.c)
target_link_libraries(DustAgent DustAgentLibrary)
add_executable(DustAgentTest test.c)
target_link_libraries(DustAgentTest DustAgentLibrary gtest)
add_test(DustAgentTest DustAgentTest)