guitargeek / XGBoost-FastForest

Minimal library code to deploy XGBoost models in C++.
MIT License
89 stars 30 forks source link

std::length_error issue #13

Closed TimWZH closed 3 years ago

TimWZH commented 3 years ago

Hi,

I got std::length_error when I was trying to build and run example codes on windows visual studio 2017. I have no idea what is wrong here. Could you help me with it?

Thanks,

image image image

Building information:

$ cmake -DCMAKE_GENERATOR_PLATFORM=x64  -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.16.27045.0
-- The CXX compiler identification is MSVC 19.16.27045.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: C:/local/boost_1_71_0 (found version "1.71.0") found components: system filesystem unit_test_framework
-- Configuring done
-- Generating done
-- Build files have been written to: E:/workspace/c/XGBoost-FastForest/build2
$ cmake --build . --config Release
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  fastforest_functions.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xlocale(319): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [E:\workspace\c\XGBoost-FastForest\build2\fastforest.vcxproj]
  Auto build dll exports
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification [E:\workspace\c\XGBoost-FastForest\build2\fastforest.vcxproj]
     Creating library E:/workspace/c/XGBoost-FastForest/build2/Release/fastforest.lib and object E:/workspace/c/XGBoost-FastForest/build2/Release/fastforest.exp
  fastforest.vcxproj -> E:\workspace\c\XGBoost-FastForest\build2\Release\fastforest.dll
  Test.vcxproj -> E:\workspace\c\XGBoost-FastForest\build2\test\Release\Test.exe
guitargeek commented 3 years ago

Hi @TimWZH! I have no knowledge about the Microsoft C++ compiler at all. So the code compiles and then it throws this string too long error when you run it?

I would try to rewrite this line and hope that it works if you do the same thing in a different way. Maybe try:

const std::string info = std::string("constructing FastForest from ") + txtpath + std::string(": ");

If you find a way to create the same info string that works on Visual studio, I'd be happy about a pull request!

If it doesn't work, you can also leave the info string empty in your fastforest build, it's only used for error messages anyway:

const std::string info;

Let me know if any of the solutions work!

Cheers, Jonas

TimWZH commented 3 years ago

Hi Jonas,

I find that it is likely that load_txt function does not receive correct parameters.

When I try to pass parameter std::vector<std::string> features{ "f0", "f1", "f2", "f3", "f4" }; I got this when debugging:

image

And this for txtpath:

image

But it is okay when I try these code :

#include <iostream>
#include <cmath>
#include <iostream>
#include <vector>

void test(std::string const& txtpath, std::vector<std::string>& fea) {
    const std::string info = "constructing FastForest from " + txtpath + ": ";
}

int main()
{
    std::vector<std::string> features{ "f0",  "f1",  "f2",  "f3",  "f4" };
    test("model.txt",features); 
    return 0;
}
image

Do you know why?

Thanks, Tim

guitargeek commented 3 years ago

Hi Tim, sorry for the late reply! What happens here is quite strange.

The messages about variables being optimized away reminds me that it could be an optimization issue. Have you tried to compile fastforest without the optimization flag? You can do that just by removing the -O2 in this line in CMakeLists.txt.

TimWZH commented 3 years ago

Hi Jonas,

Thanks for your help! I realized that I added additional optimization commands when compiling. So now I use your original CmakeLists.txt and it works!