Open dczaretsky opened 3 years ago
Thanks for the info. It was useful although I needed to build .lib for windows with visual studio. My first attempt was use GN build tool and modify BUILD.gn файл. It was very straight forward but unfortunately chrome uses clang and use_clang = false is not available. I used this setup
gn gen --args="is_debug=false is_component_build=false target_cpu=\"x64\" use_lld=false" out/x64.release
On theory using VS2019 with clang should work but I got many unresolved externals during the linking and I gave up.
My approach to this was to avoid clang and build all dependencies with VS2017
Follow the steps for buidling cld_3
Build protobuf from source with Visual Studio and cmake matching the chromium protobuf version (currently 3.9.0) Directory location of the source C:/protobuf/protobuf-3.9.0
Add these lines to C:\chromium\src\third_party\cld_3\src\CMakeList.txt with correct path pointing to your directory location
Add this as first line in the file cmake_policy(SET CMP0091 NEW) to allow usage of CMAKE_MSVC_RUNTIME_LIBRARY
set (Protobuf_INCLUDE_DIR "C:/protobuf/protobuf-3.9.0/src") set (Protobuf_LIBRARIES "C:/protobuf/protobuf-3.9.0/cmake/build/solution/Release") set (Protobuf_LITE_LIBRARIES "C:/protobuf/protobuf-3.9.0/cmake/build/solution/Release") set (Protobuf_PROTOC_EXECUTABLE "C:/protobuf/protobuf-3.9.0/cmake/build/solution/Release/protoc.exe") set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
I am not sure if this is needed but I added it because of the post above
install(DIRECTORY include/ DESTINATION include) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
replace add_executable(language_identifier_main src/language_identifier_main.cc) target_link_libraries(language_identifier_main cld3 ${Protobuf_LITE_LIBRARIES})
with link_directories(C:/protobuf/protobuf-3.9.0/cmake/build/solution/Release) add_executable(language_identifier_main src/language_identifier_main.cc) target_link_libraries(language_identifier_main cld3 ${Protobuf_LITE_LIBRARIES}) target_link_libraries(language_identifier_main cld3 libprotobuf.lib) target_link_libraries(language_identifier_main cld3 libprotobuf-lite.lib) target_link_libraries(language_identifier_main cld3 libprotoc.lib)
cd "C:\chromium\src\third_party\cld_3\src" mkdir build cd build
cmake -G "Visual Studio 15 2017 Win64" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../..
You should be able to build language_identifier_main.vcproj.
https://gist.github.com/ekalchev/493c3790cdb7378dc7d1db48fabc8705
@dczaretsky , Thanks for the steps able to successfully build libcld3.a but When am trying to execute the C++ code am getting following error in RHEL, any idea
cld3test.cc:(.text+0x6f): undefined reference to
chrome_lang_id::NNetLanguageIdentifier::NNetLanguageIdentifier()'
cld3test.cc:(.text+0x8f): undefined reference to chrome_lang_id::NNetLanguageIdentifier::FindLanguage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' cld3test.cc:(.text+0x111): undefined reference to
chrome_lang_id::NNetLanguageIdentifier::~NNetLanguageIdentifier()'
cld3test.cc:(.text+0x166): undefined reference to chrome_lang_id::NNetLanguageIdentifier::~NNetLanguageIdentifier()'
@gnanaravindhan sounds like maybe the library was not linked to your program or include files were not found. You might want to check where the include and lib files were installed, then compile with -I and -L parameters to provide their paths respectively, like this:
g++ -I/usr/local/include -L/usr/local/lib -lcld3 cld3test.cc -o cld3test
g++ -I/usr/local/include -L/usr/local/lib -lcld3 cld3test.cc -o cld3test
@dczaretsky Thanks for your response, as recommended i've tried the same, but no luck. following is the command which am executing
g++ -I/opt/rh/vcpkg/installed/x64-linux/include -I/usr/local/include -L/usr/local/lib -lcld3 cld3test.cc -o cld3test
I've sorted out the issue, after changing the
-D_GLIBCXX_USE_CXX11_ABI=0
to -D_GLIBCXX_USE_CXX11_ABI=1
it's started working fine.
@dczaretsky Thanks for your help
According to the CMake configuration, you should include the -std=c++11 option for g++. I'm using -std=c++14 in my program compilation, and that also works.
I have error as below, could you please help me how to solve it?
cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --target install
output is: `C:\Users\HardW\Downloads\cld3-master\build.release>cmake .. -DCMAKE_BUILD_TYPE=Release CMake Error at CMakeLists.txt:3 (project): Running
'nmake' '-?'
failed with:
The system cannot find the file specified
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred! See also "C:/Users/HardW/Downloads/cld3-master/build.release/CMakeFiles/CMakeOutput.log"`
In order to include this library in another C++ program, the libcld3.a and include files need to be installed. However, the makefile does not include support for this right now. I was able to add that support by appending the following code to the CMakeLists.txt file:
You will need to create an /include directory with all the *.h files. Then you can compile and install the library as follows:
Using cld3 in your program is pretty simple:
Hope this helps anyone who might be stuck.