I’m trying to compile an appliation, in Windows, in Conda, with VS2019.
My CMakeLists.txt file:
cmake_minimum_required(VERSION 3.10)
project(MyProject)
find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(my_program po_demo.cpp)
target_link_libraries(my_program Boost::program_options)
My example application:
#include <iostream>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
int main(int argc, char** argv) {
try {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("input-file", po::value<std::string>(), "set input file")
("output-file", po::value<std::string>(), "set output file")
("verbose,v", "enable verbose output")
("optimization-level", po::value<int>()->default_value(0), "set optimization level")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << "Usage: program_name [options]n";
std::cout << desc;
return 0;
}
} catch (const po::error& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
} catch (std::exception ex) {
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
catch (...) {
std::cerr << "Error unknown" << std::endl;
return 1;
}
return 0;
}
I create an environment (from a miniforge3 prompt):
conda create -n potest
conda activate potest
conda install cxx-compiler libboost-devel cmake make
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=%CONDA_PREFIX% -G "Unix Makefiles" ..
make
Program output:
Error: bad allocation
CMake reports that it finds the boost library in the environment. dumpbin reports the following:
Dump of file my_program.exe
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
boost_program_options.dll
MSVCP140D.dll
VCRUNTIME140D.dll
VCRUNTIME140_1D.dll
ucrtbased.dll
KERNEL32.dll
Summary
1000 .00cfg
2000 .data
4000 .idata
3000 .pdata
B000 .rdata
1000 .reloc
1000 .rsrc
1F000 .text
1000 .tls
The issue occurs on the very first line of the application. If I change from po::options_description desc("Allowed options");
to po::options_description desc;
then we will instead continue until po::notify
and the error will instead be: Error: vector too long
. Additionally it will pop up this dialog:
I’m pretty confused. Should this work? Is there a compatibility issue between the conda versions of boost and this compiler?
4
The conda’s boost library in windows doesn’t include the debug versions. See here.
I was attempting to build with CMAKE_BUILD_TYPE=Debug which then caused a mix of debug and non-debug libraries. I wasn’t aware that this was a problem as it appears to be a minor issue in Linux. But in windows it appears to be a very big issue.
Thank you Botje for the information.