Closed hkundnani closed 3 years ago
@hkundnani Sorry for the late response!
I'm not the expert on the C++ API, so I will make sure someone else takes a look at this too. My initial thought from the error message though is that you might need to link dynamically with boost by adding -lboost
as an additional compile flag. Try that while I get someone else to take a look.
Thanks for trying out the C++ API and reporting your issue!
@gustavla Thank you for your response.
I will try adding the additional compile flag -lboost
and update my findings.
Does it work if you leave off the libunity.a include at the end? unity_shared should have everything needed. If you add in libunity.a, then I think you'll have to add in a lot of other libXXXX.a files as well to get the missing symbols.
@hkundnani I am not able to reproduce this issue; though I do initially get the error:
../turicreate/src/unity/toolkits/coreml_export/protobuf_include_internal.hpp:25:10: fatal error: 'google/protobuf/text_format.h' file not found
Which I am able to fix by adding to the command:
-I../turicreate/src/external
Would you mind sharing the commit/tag/version you're building with, and (if it has changed from the documentation) your model_predict.cpp as well? Thanks!
@znation I am working with release version 4.3.2 and I did run it by adding the command:
-I../turicreate/src/external
but I still get the same error log I shared previously. I think my error is related to boost where I see these three errors message:
/home/castl/turicreate/deps/local/include/boost/system/error_code.hpp:206: undefined reference to `boost::system::generic_category()'
/home/castl/turicreate/deps/local/include/boost/system/error_code.hpp:208: undefined reference to `boost::system::generic_category()'
/home/castl/turicreate/deps/local/include/boost/system/error_code.hpp:210: undefined reference to `boost::system::system_category()'
@hoytak When I leave off the libunity.a while compiling
c++ -std=c++11 -I../turicreate/src -I../turicreate/src/external -I../turicreate/src/platform -I../turicreate/deps/local/include -I../turicreate/src/external/armadillo/include -DHASH_FOR_UINT128_DEFINED -DHASH_FOR_INT128_DEFINED -L../turicreate/release/src/unity -lunity_shared model_predict.cpp
The three errors mentioned above are resolved I guess but I still get these errors:
/tmp/cc73V3tx.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
model_predict.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8): undefined reference to `boost::system::generic_category()'
model_predict.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3): undefined reference to `boost::system::generic_category()'
/tmp/cc73V3tx.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
model_predict.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8): undefined reference to `boost::system::generic_category()'
model_predict.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3): undefined reference to `boost::system::generic_category()'
model_predict.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1ce): undefined reference to `boost::system::generic_category()'
So in both cases I know it's realted to boost. I am just unable to figure out if I am missing some environement variable or I need to pass some additional flag while compiling which would remove these boost library errors.
@znation My model_predict.cpp file is same as shown in example of the documentation (https://apple.github.io/turicreate/docs/userguide/cpp.html). I have created mushroom.tcmodel and it's in the same directory as the model_predict.cpp. I am not sharing the model code here since that is also same from the documentation however, I am sharing the model_predict.cpp.
// standard C++ includes
#include <iostream>
// Turi Create includes
#include <logger/assertions.hpp>
#include <logger/logger.hpp>
#include <unity/lib/unity_global.hpp>
#include <unity/server/registration.hpp>
#include <unity/toolkits/supervised_learning/boosted_trees.hpp>
int main(int argc, char **argv) {
// set up registry of named functions and models
// used for rehydrating saved models
auto fn_reg = turi::toolkit_function_registry();
turi::register_functions(fn_reg);
auto class_reg = turi::toolkit_class_registry();
turi::register_models(class_reg);
// create a global context
auto global = turi::unity_global(&fn_reg, &class_reg);
// load the model from disk
auto loaded_model = global.load_model("mushroom.tcmodel");
std::string name = turi::variant_get_value<turi::flexible_type>(loaded_model["model_name"]);
std::cout << "Loaded model: " << name << std::endl;
auto model = std::dynamic_pointer_cast<turi::supervised::xgboost::boosted_trees_classifier>(
turi::variant_get_value<std::shared_ptr<turi::model_base>>(loaded_model["model"])
);
// set up input
// (note: can do batch prediction by adding more than one row to rows)
std::vector<turi::flexible_type> rows;
turi::flex_dict row;
row.push_back(std::make_pair("bruises?", "t"));
row.push_back(std::make_pair("cap-color", "n"));
row.push_back(std::make_pair("cap-shape", "x"));
row.push_back(std::make_pair("cap-surface", "s"));
row.push_back(std::make_pair("gill-attachment", "f"));
row.push_back(std::make_pair("gill-color", "k"));
row.push_back(std::make_pair("gill-size", "n"));
row.push_back(std::make_pair("gill-spacing", "c"));
row.push_back(std::make_pair("habitat", "u"));
row.push_back(std::make_pair("odor", "p"));
row.push_back(std::make_pair("population", "s"));
row.push_back(std::make_pair("ring-number", "o"));
row.push_back(std::make_pair("ring-type", "p"));
row.push_back(std::make_pair("spore-print-color", "k"));
row.push_back(std::make_pair("stalk-color-above-ring", "w"));
row.push_back(std::make_pair("stalk-color-below-ring", "w"));
row.push_back(std::make_pair("stalk-root", "e"));
row.push_back(std::make_pair("stalk-shape", "e"));
row.push_back(std::make_pair("stalk-surface-above-ring", "s"));
row.push_back(std::make_pair("stalk-surface-below-ring", "s"));
row.push_back(std::make_pair("veil-color", "w"));
row.push_back(std::make_pair("veil-type", "p"));
rows.push_back(row);
// make prediction
turi::gl_sframe result = model->fast_predict_topk(
// input data - 1 row per prediction
rows,
// output type - see https://github.com/apple/turicreate/blob/3490286b27ff5d79cb90d09fe026d5671ce990c7/src/unity/toolkits/supervised_learning/supervised_learning.hpp#L47
"probability",
// missing value action - see https://github.com/apple/turicreate/blob/3490286b27ff5d79cb90d09fe026d5671ce990c7/src/ml_data/ml_data_column_modes.hpp#L27
"error",
// k (returns top k predictions) -- must be <= the number of classes
2
);
std::string row_str = rows[0].to<std::string>(); // turn first row of input into a string
std::cout << "Input to model: " << row_str << std::endl;
std::cout << "Predicted: " << result << std::endl;
}
I also tried compiling by adding the flag -lboost
:
c++ -std=c++11 -lboost -I../turicreate/src -I../turicreate/src/external -I../turicreate/src/platform -I../turicreate/deps/local/include -I../turicreate/src/external/armadillo/include -DHASH_FOR_UINT128_DEFINED -DHASH_FOR_INT128_DEFINED -L../turicreate/release/src/unity -lunity_shared model_predict.cpp ../turicreate/release/src/unity/libunity.a
but then I get this error:
In file included from ../turicreate/src/generics/type_trait_def.hpp:19:0,
from ../turicreate/src/generics/remove_member_pointer.hpp:30,
from ../turicreate/src/cppipc/client/issue.hpp:15,
from ../turicreate/src/cppipc/client/comm_client.hpp:21,
from ../turicreate/src/cppipc/client/object_proxy.hpp:10,
from ../turicreate/src/cppipc/magic_macros.hpp:9,
from ../turicreate/src/unity/lib/api/model_interface.hpp:13,
from ../turicreate/src/unity/lib/toolkit_class_base.hpp:13,
from ../turicreate/src/unity/lib/toolkit_class_macros.hpp:12,
from ../turicreate/src/unity/lib/visualization/plot.hpp:4,
from ../turicreate/src/unity/lib/api/unity_sarray_interface.hpp:13,
from ../turicreate/src/unity/lib/api/unity_global_interface.hpp:12,
from ../turicreate/src/unity/lib/unity_global.hpp:13,
from model_predict.cpp:7:
../turicreate/deps/local/include/boost/type_traits/detail/template_arity_spec.hpp:13:84: note: #pragma message: NOTE: Use of this header (template_arity_spec.hpp) is deprecated
# pragma message("NOTE: Use of this header (template_arity_spec.hpp) is deprecated")
^
In file included from ../turicreate/src/util/dense_bitset.hpp:16:0,
from ../turicreate/src/sframe/sarray_file_format_v2.hpp:16,
from ../turicreate/src/sframe/sarray.hpp:20,
from ../turicreate/src/sframe/sframe.hpp:14,
from ../turicreate/src/unity/lib/unity_base_types.hpp:10,
from ../turicreate/src/unity/lib/unity_global.hpp:9,
from model_predict.cpp:7:
../turicreate/src/util/bitops.hpp: In instantiation of ‘unsigned int turi::num_bits_on(T, typename std::enable_if<(((((((std::is_same<T, unsigned char>::value || std::is_same<T, short unsigned int>::value) || std::is_same<T, unsigned int>::value) || std::is_same<T, long unsigned int>::value) || std::is_same<T, unsigned int>::value) || std::is_same<T, long unsigned int>::value) || std::is_same<T, long long unsigned int>::value) || std::is_same<T, __int128 unsigned>::value)>::type*) [with T = long unsigned int; typename std::enable_if<(((((((std::is_same<T, unsigned char>::value || std::is_same<T, short unsigned int>::value) || std::is_same<T, unsigned int>::value) || std::is_same<T, long unsigned int>::value) || std::is_same<T, unsigned int>::value) || std::is_same<T, long unsigned int>::value) || std::is_same<T, long long unsigned int>::value) || std::is_same<T, __int128 unsigned>::value)>::type = void]’:
../turicreate/src/util/dense_bitset.hpp:177:57: required from here
../turicreate/src/util/bitops.hpp:156:59: warning: right shift count >= width of type [-Wshift-count-overflow]
+ __builtin_popcountll((unsigned long long)(v >> 64)));
^
../turicreate/src/util/bitops.hpp:162:10: warning: right shift count >= width of type [-Wshift-count-overflow]
vt >>= bitsizeof(unsigned long long);
^
/usr/bin/ld: cannot find -lboost
collect2: error: ld returned 1 exit status
It can't find -lboost.
Is this still an issue?
I have not heard back here. I'm going to close this issue. Feel free to reopen if it's still an issue.
I am trying to use the C++ API and was referring to the doc available under userguide directory. While trying to compile the example code provided in the guide I am getting errors "undefined reference to boost::system::generic_category(), undefined reference to `boost::system::system_category()". I have attached the compilation log for the reference.
I am not sure if I am missing something or if the error is in the code. While compiling I passed all the parameters as mentioned in the guide. my code model_predict.cpp was in the sibling directory so the compilation instruction that I passed was this
Also, I am using the release v4.3.2.