error: ‘invalid_argument’ is not a member of ‘std’
- User
error: ‘invalid_argument’ is not a member of ‘std’
- Assistant
The error message you're encountering, "error: ‘invalid_argument’ is not a member of ‘std’", suggests that your code is trying to use the
std::invalid_argumentexception class, but the compiler can't find it. This usually implies that the appropriate header file hasn't been included.The
std::invalid_argumentclass is defined in the C++ Standard Library, specifically in the<stdexcept>header. To resolve this issue, you should include the necessary header at the top of your code file.Here’s how to fix the error:
- Make sure to include at the beginning of your source file:
- User
cmake_minimum_required(VERSION 3.13)
project(google_test)
add_library(calc_lib STATIC calculator.cpp)
add_executable(calculator main.cpp) target_link_libraries(calculator calc_lib)
how to create the dynamic library for the calculator
- Assistant
To create a dynamic (shared) library in CMake instead of a static library, you need to modify the
add_libraryfunction to specify that you want to create a shared library.Here's how you can modify your existing
CMakeLists.txtfile to create a dynamic library for thecalculator:cmake_minimum_required(VERSION 3.13) project(google_test) # Create a shared library instead of a static one add_library(calc_lib SHARED calculator.cpp) add_executable(calculator main.cpp) target_link_libraries(calculator calc_lib) - User
my cmakelist is inside a folder and i created a build folder outside the source folder.. how i can build
- Assistant
When you have your
CMakeLists.txtfile in a source folder and you want to build the project in a separate build directory (usually the recommended approach), you can do that with the following steps: - User
or I need to keep the CmakeList out side the source folder how that code change
- Assistant
If you want to keep your
CMakeLists.txtfile outside of your source folder while still organizing your source code in its own directory, you need to adjust the paths in yourCMakeLists.txtaccordingly.Updated Project Structure
If you choose to keep the
CMakeLists.txtfile outside of the source folder, your project directory structure might look like this:/parent_directory CMakeLists.txt # The CMake configuration file /my_project calculator.cpp main.cpp - User
add_library(calc_lib SHARED my_project/calculator.cpp) need to add all the links like a SOURCE PAth
- Assistant
- User
need to set the source path also
- Assistant
- User
need to set the path as default means my application run in this "/mnt/d/Training_Materials/Gtest/src " path. So Cmake should be in Gtest folder and source files in src.. amke change according to this and make a proffessional cmake
- Assistant
- User
CMake Error at CMakeLists.txt:15 (target_include_directories): Cannot specify include directories for target "calc_lib" which is not built by this project.
- Assistant
- User
add executable and .so removal
- Assistant
- User
no remove the binary and all that
- Assistant
- User
no remove generated binary by make clean
- Assistant
- User
how we can remove the binary file in build folder using " make clean"
- Assistant