I am trying to use boost libraries in VSCode (using Cmake & vcpkg) but can't seem to figure out what's wrong. I installed Boost in vcpkg.
Here are the error messages.
main.cpp
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t boost_product(long long A, long long B)
{
int128_t ans = (int128_t) A * B;
return ans;
}
int main()
{
long long first = 98745636214564698;
long long second=7459874565236544789;
cout << "Product of "<< first << " * "
<< second << " = \n"
<< boost_product(first,second) ;
return 0;
}
setting.json
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
CmakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(demo VERSION 0.1.0)
include(CTest)
enable_testing()
add_executable(demo main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Errors:
main.cpp:1:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
1 | #include <boost/multiprecision/cpp_int.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Maybe I am missing something. Please help.Thank you!
Related
Here is my code, it correct without CMAKE_CXX_FLAGS "-m32"
#include <iostream>
using namespace std;
int main() {
void *startPos;
cout << startPos << endl;
return 0;
}
It says Use of undeclared identifier 'cout'
Here is my Cmakelist
cmake_minimum_required(VERSION 3.16)
project(test)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "-m32")
include_directories(${PROJECT_SOURCE_DIR}/include)
add_executable(test src/test.cpp)
I'm using wsl2 ubuntu20.04
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
This is my dir tree (root dir is untitled)
This is the content of CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(untitled)
set(CMAKE_CXX_STANDARD 11)
find_package (OpenCV 4.5.2 REQUIRED)
include_directories ("/usr/local/include/opencv4/")
add_executable(untitled main.cpp)
This is my code in main.cpp:
#include <iostream>
#include <string>
#include <sstream>
#include <opencv4/opencv2/core.hpp>
#include <opencv4/opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, const char** argv) {
Mat color = imread("./lenna.png");
Mat gray = imread("./lenna.png", 0);
imwrite("./lennaGray.png", gray);
int myRow = color.cols - 1;
int myCol = color.rows - 1;
Vec3b pixel = color.at<Vec3b>(myRow, myCol);
cout << "Pixel value (B, G, R): (" << (int)pixel[0] << ", " << (int)pixel[1] << ", " << (int)pixel[2] << ")" << endl;
imshow("Lenna BGR", color);
imshow("Lenna Gray", gray);
waitKey(0);
return 0;
}
This is the entire error when I ran make command:
But if I ran my code in terminal by this command:
g++ main.cpp -o main -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4 && ./main
then it worked.
I don't know what happened, I just learned OpenCV and I am using Ubuntu 20.04 and OpenCV-4.5.2.
I am trying to use the opencv QRCodeDetector class in one of my functions, but unfortunately I am getting an error.
The error is saying that QRCodeDetector is not a member of cv.
C++ function code (test_qr.cpp):
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <string>
void qrCheck(std::vector<std::string>& qrStorage, cv::Mat imageLeft_t0) {
cv::QRCodeDetector qrDecoder = cv::QRCodeDetector(); // Error on this line
std::string data = qrDecoder.detectAndDecode(imageLeft_t0);
if (data.length() > 0) {
std::cout << "QR Decoded Data: " << data << std::endl;
qrStorage.push_back(data);
} else
std::cout << "QR Code Not Detected" << std::endl;
}
In case you want to see my cmake file:
cmake_minimum_required(VERSION 3.11)
project( DisplayImage )
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable( DisplayImage test_qr.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
I also tried doing something similar to this: ‘BackgroundSubtractorMOG’ is not a member of ‘cv’
But it didn't help.
I need to install OpenMP on my Mac and use it in CLion. I re-installed gcc, confirmed I have it, /usr/bin/local/gcc-7. Do not understand if this comes with OpenMP or if I need to install something extra.
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
project(lab_3)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
add_executable(lab_3 main.cpp)
main.cpp
#include <iostream>
#include <omp.h>
int main() {
#pragma omp parallel for
for (int i=0; i<10; i++) {
std::cout << "This is thread #" << omp_get_thread_num() << std::endl;
}
return 0;
}
Error message:
clang: error: unsupported option '-fopenmp'
I am using the poppler-cpp library in my project.
It build & start it correctly, but I need to have popple installed in my system.
What is the way to import (include) the poppler library in my project, the aim is to execute it on another linux system which has not poppler lib installed, is it possible ?
My current cmakeList.txt file:
cmake_minimum_required(VERSION 3.5)
project(poppler_test)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/extra-cmake-modules/find-modules")
find_package(Poppler REQUIRED)
include(CMakeToolsHelpers OPTIONAL)
include_directories(${Poppler_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
ADD_LIBRARY(poppler STATIC IMPORTED)
add_dependencies( poppler poppler_test )
add_executable(poppler_test ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${Poppler_LIBRARIES})
My main.cpp Programm
#include <algorithm>
#include <cpp/poppler-document.h>
#include <cpp/poppler-page.h>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
auto input = "/Home/Dev/poppler-test/test.pdf";
shared_ptr<poppler::document> doc{poppler::document::load_from_file(input)};
const int pagesNbr = doc->pages();
cout << "page count: " << pagesNbr << endl;
vector<string> infoKeys{doc->info_keys()};
for_each(infoKeys.begin(), infoKeys.end(),
[doc](string infoKey) { cout << doc->info_key(infoKey).to_latin1() << endl; });
for (int i = 0; i < pagesNbr; ++i) {
shared_ptr<poppler::page> currentPage{doc->create_page(i)};
if (currentPage == nullptr) {
auto byteArrayResult = currentPage->text().to_utf8();
string result{byteArrayResult.begin(), byteArrayResult.end()};
cout << result << endl;
}
}
}