JetBrains CLion can not suggest member methods of string - c++

I'm new to JetBrains' CLion. Sorry if my question is basic but I didn't find any answer by searching.
#include <string>
int main() {
std::string str;
str.assign("ABC");
}
This very simple code compiles fine but the problem is the editor can't suggest member methods for str.
I'm using CLion 2016.3.2 on Fedora 25
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(ITP)
set(CMAKE_CXX_STANDARD "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(/usr/include /usr/local/include /usr/local/pgsql/include)
set(SOURCE_FILES
main.cpp
commander.cpp
)
add_custom_target(ITP command make -C /home/ben/projects/ITP)
Note: when I point to #include the editor didn't knows relevant include file!

Finally I reached to an answer!
Clion works with Cmake. there for CMakeLists.txt is very important.
many settings with cmake can effect code compilation, build types and ...
for more details please see my new CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(ITP)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
set(SOURCE_FILES
main.cpp
commander.cpp)
link_directories(/usr/local/pgsql/lib/)
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message("C Flags = ${CMAKE_CXX_FLAGS_DEBUG}")
add_executable(itp OrderManagementSystem/main.cpp)
add_custom_command(
TARGET itp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/config.ini
${CMAKE_CURRENT_BINARY_DIR})
TARGET_LINK_LIBRARIES( itp
pthread
boost_system boost_thread
protobuf
zmq
pq
)
I'm new with both Clion and cmake. but these two ..

Related

How to use CMake to compile *.cpp and *.cu seperately?

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 .

CMake does not build the added sub-directory first

I am writing a C++ project that uses Poco Net library. I use CMake to configure the project.
I would like to add Poco as a sub-directory to my project so that it is built in my main project. Here is my shortened main CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(FunProj)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode...")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(HEADER_FILES IDataProvider.h DataProvider.h)
set(SOURCE_FILES main.cpp
DataProvider.cpp)
set(POCO_STATIC ON)
ADD_SUBDIRECTORY(poco)
include_directories(${CMAKE_SOURCE_DIR}/poco/Net/include)
include_directories(${CMAKE_SOURCE_DIR}/poco/Foundation/include)
link_directories(${CMAKE_CURRENT_BINARY_DIR}/poco/lib)
add_executable(FunProj ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(${EXEC_NAME} PocoNet)
When I run cmake it configures everything including Poco but when I run make it does not compile the Poco libraries. It only compiles the main.o and DataProvider.o and then the linker fails with an error that libPocoNet.a does not exist.
What is the problem and how may one solve it?
Thank you.

Dynamic link error cmake

When I compile my code using command line everything works fine:
g++ main.cpp -lpngwriter
But when I try using cmake I get undefined reference errors.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(myproject)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpngwriter")
set(SOURCE_FILES main.cpp)
add_executable(myproject ${SOURCE_FILES})
Any ideas how to fix it?
Consider adding include_directories(/path/to/include) and link_directories(/path/to/lib) before add_executable().
And then insert target_link_libraries(pngwriter) after add_executable().
/path/to shall be replaced with relevant values for your system.

Unable to locate SimpleAmqpClient library for the C++ project on OSX

I try to use the SimpleAmqpClient library to build my multi-agent environment for simulation. I have installed the library after cloning its sources, making them:
make
sudo make install
After that, I created the
main.cpp
file:
#include <iostream>
#include <SimpleAmqpClient/SimpleAmqpClient.h>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
just to try it out.
Also, I have the following
CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(SampleProject)
include_directories('/usr/local/include/')
find_package(libSimpleAmqpClient REQUIRED)
include_directories(${libSimpleAmqpClient++_INCLUDE_DIRS})
set(LIBS ${LIBS} ${libSimpleAmqpClient++_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(SampleProject ${SOURCE_FILES})
So, the question is: how to find and link this library.
You need to include the line
target_link_libraries(SampleProject ${LIBS})
after the line
add_executable(SampleProject ${SOURCE_FILES})
This imbues the target SampleProject with properties that tell the generator to generate a linker command which reference the libraries you need.
I have found the solution, thanks to #RichardHodges. The solution was to use
find_library() instead of find_package().
THe final file is the following:
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(SampleProject)
include_directories('/usr/local/include/')
find_library(libSimpleAmqpClient REQUIRED)
include_directories(${libSimpleAmqpClient++_INCLUDE_DIRS})
set(LIBS ${LIBS} ${libSimpleAmqpClient++_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(SampleProject ${SOURCE_FILES})

CMakeLists C program with gtest(C++)

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)