Compling Error
Hi:
I am trying to compile ChargeFW2 in my local Ubuntu 22.04 machine. The compiling error shows as follow:
[ 74%] Linking CXX executable chargefw2
cd /home/jrwang/Git/ChargeFW2/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/chargefw2.dir/link.txt --verbose=1
/usr/bin/c++ -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wsign-promo -Wstrict-null-sentinel -Wundef -Wno-unused -Wno-format-y2k -fPIC -march=native -fopenmp -fsized-deallocation -O3 -DNDEBUG -flto -fno-fat-lto-objects -s CMakeFiles/chargefw2.dir/main.cpp.o CMakeFiles/chargefw2.dir/periodic_table.cpp.o CMakeFiles/chargefw2.dir/charges.cpp.o CMakeFiles/chargefw2.dir/statistics.cpp.o CMakeFiles/chargefw2.dir/candidates.cpp.o -o chargefw2 -Wl,-rpath,/home/jrwang/anaconda3/lib: structures/libstructures.a libparameters.a libgeometry.a libelement.a libmethod.a libconfig.a formats/libformats.a utility/libutility.a /home/jrwang/anaconda3/lib/libboost_program_options.so.1.82.0 -ldl /home/jrwang/anaconda3/lib/libboost_filesystem.so.1.82.0 structures/libstructures.a libgeometry.a structures/libstructures.a libgeometry.a utility/libutility.a /home/jrwang/anaconda3/lib/libfmt.so.9.1.0 /home/jrwang/anaconda3/lib/libboost_atomic.so.1.82.0
lto-wrapper: warning: using serial compilation of 13 LTRANS jobs
/usr/bin/ld: /tmp/ccUtzshP.ltrans6.ltrans.o: in function gemmi::Structure gemmi::pdb_impl::read_pdb_from_stream<gemmi::FileStream>(gemmi::FileStream&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, gemmi::PdbReadOptions const&)': <artificial>:(.text+0x3fd4): undefined reference to gemmi::assign_subchains(gemmi::Structure&, bool, bool)'
/usr/bin/ld: gemmi::change_ccd_code(gemmi::Structure&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /usr/bin/ld: <artificial>:(.text+0x6083): undefined reference to gemmi::remove_entity_types(gemmi::Structure&)'
/usr/bin/ld: /tmp/ccUtzshP.ltrans8.ltrans.o: in function mmCIF::process_record(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<std::vector<Molecule, std::allocator<Molecule> >, std::default_delete<std::vector<Molecule, std::allocator<Molecule> > > >&)': <artificial>:(.text+0x6b69): undefined reference to gemmi::make_structure_from_block(gemmi::cif::Block const&)'
/usr/bin/ld: /tmp/ccUtzshP.ltrans10.ltrans.o: in function `generate_mmcif_from_block(gemmi::cif::Block&, MoleculeSet const&, Charges const&, std::__cxx11::basic_string<char, std::char_traits
All errors come from Gemmi library. I have already install the gemmi-dev in my machine. It seems that linker can not find Gemmi library. However, the Gemmi is a C++ head-only library. Can anybody help me?
hi, i think you should add "find_package(gemmi 0.6.5 CONFIG REQUIRED)" in file src/CMakeLists.txt Line 6 and "target_link_libraries(chargefw2 gemmi::gemmi_cpp)" in file src/CMakeLists.txt Line 34 and "target_link_libraries(chargefw2_gp PRIVATE gemmi::gemmi_cpp)" in file src/CMakeLists.txt Line 51
here is my src/CMakeLists.txt
find_package(Boost COMPONENTS program_options system filesystem REQUIRED)
find_package(fmt 5.3 REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(nanoflann 1.3 REQUIRED)
find_package(pybind11)
find_package(gemmi 0.6.5 CONFIG REQUIRED)
include_directories(${PROJECT_BINARY_DIR}/src)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
configure_file(chargefw2.h.in chargefw2.h)
SET(COMMON_LIBS parameters geometry element method config)
foreach (lib ${COMMON_LIBS})
add_library(${lib} ${lib}.h ${lib}.cpp)
target_link_libraries(${lib} structures fmt::fmt)
endforeach ()
target_link_libraries(method Eigen3::Eigen)
add_subdirectory(structures)
add_subdirectory(methods)
add_subdirectory(formats)
add_subdirectory(utility)
SET(SOURCES main.cpp periodic_table.cpp periodic_table.h charges.h charges.cpp statistics.h statistics.cpp
candidates.h candidates.cpp)
add_executable(chargefw2 ${SOURCES})
add_dependencies(chargefw2 ${METHODS})
target_link_libraries(chargefw2 structures ${COMMON_LIBS} formats utility Boost::program_options dl Boost::filesystem fmt::fmt)
target_link_libraries(chargefw2 gemmi::gemmi_cpp)
set_target_properties(chargefw2 PROPERTIES LINK_FLAGS_RELEASE -s)
install(TARGETS chargefw2 DESTINATION bin)
# Install files required for independent building of new methods
add_library(libchargefw2 STATIC element.h element.cpp method.cpp method.h parameters.h parameters.cpp
structures/molecule.h structures/molecule.cpp geometry.h geometry.cpp periodic_table.h periodic_table.cpp)
set_target_properties(libchargefw2 PROPERTIES OUTPUT_NAME chargefw2 INTERPROCEDURAL_OPTIMIZATION FALSE)
install(TARGETS libchargefw2 ARCHIVE DESTINATION lib)
install(FILES structures/atom.h structures/bond.h structures/molecule.h DESTINATION include/structures)
install(FILES element.h method.h parameters.h geometry.h periodic_table.h DESTINATION include)
pybind11_add_module(chargefw2_gp python_gp.cpp ${SOURCES})
target_link_libraries(chargefw2_gp PRIVATE libchargefw2 formats ${COMMON_LIBS} utility Boost::program_options)
target_link_libraries(chargefw2_gp PRIVATE gemmi::gemmi_cpp)
install(TARGETS chargefw2_gp DESTINATION lib)
pybind11_add_module(chargefw2_python python.cpp ${SOURCES})
target_link_libraries(chargefw2_python PRIVATE libchargefw2 formats ${COMMON_LIBS} utility Boost::program_options)
install(TARGETS chargefw2_python DESTINATION lib)
Hi, thanks for the report. I updated the cmake requirements and the dockerfile. Please see if that works for you in the current version.
Hi, I have tested new cmake file with the latest version of compilation required libraries. The problem is resolved. However, I did not mention that I have to copy nanoflann.hpp to the build/src to resolve this compilation error.
base) jrwang@jrwang-System-Product-Name:~/Git/test/ChargeFW2/build$ make [ 1%] Building CXX object src/utility/CMakeFiles/utility.dir/strings.cpp.o [ 2%] Linking CXX static library libutility.a [ 2%] Built target utility [ 3%] Building CXX object src/structures/CMakeFiles/structures.dir/atom.cpp.o [ 4%] Building CXX object src/structures/CMakeFiles/structures.dir/molecule.cpp.o /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp: In member function ‘std::vector<const Atom*> Molecule::get_close_atoms(const Atom&, double) const’: /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:168:28: error: ‘ResultItem’ is not a member of ‘nanoflann’ 168 | std::vector<nanoflann::ResultItem<uint32_t , double>> results; | ^~~~~~~~~~ /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:168:50: error: template argument 1 is invalid 168 | std::vector<nanoflann::ResultItem<uint32_t , double>> results; | ^~~~~~ /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:168:56: error: expected unqualified-id before ‘>’ token 168 | std::vector<nanoflann::ResultItem<uint32_t , double>> results; | ^~ /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:169:16: error: ‘SearchParameters’ is not a member of ‘nanoflann’; did you mean ‘SearchParams’? 169 | nanoflann::SearchParameters params; | ^~~~~~~~~~~~~~~~ | SearchParams /home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:171:83: error: ‘results’ was not declared in this scope 171 | = index_->radiusSearch(atom.pos().data(), cutoff * cutoff, results, params); | ^~~~~~~
/home/jrwang/Git/test/ChargeFW2/src/structures/molecule.cpp:171:92: error: ‘params’ was not declared in this scope 171 | ex_->radiusSearch(atom.pos().data(), cutoff * cutoff, results, params); | ^~~~~~
make[2]: *** [src/structures/CMakeFiles/structures.dir/build.make:90: src/structures/CMakeFiles/structures.dir/molecule.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:525: src/structures/CMakeFiles/structures.dir/all] Error 2 make: *** [Makefile:136: all] Error 2
If I copy the .hpp to src directory, compilation will be done without problem with new cmake file.
Well, nanoflann should be detected by cmake, so the manual copy would not be necessary. See the Dockerfile using which ChargeFW2 builds correctly with Ubuntu 24.04 packages.
Anyway, I made a lot of cleanup recently, so check the latest version as well.
Hi, I'm trying to install ChargeFWII in a CentOS machine. Apparently CMake is not able to prepare correctly all the include flags. For example, the compilations stacked because nlohmann/json.hpp wasn't visible this issue soved after update the CPATH environment variable with the right path.
Now is blocked a second time but I cannot figure out where the error is.
Could someone, please, help me with this?
[ 17%] Building CXX object src/CMakeFiles/method.dir/method.cpp.o
/home/alistar/comp/ForChargesFW2/ChargeFW2/src/method.cpp: In function ‘Method* load_method(const string&)’:
/home/alistar/comp/ForChargesFW2/ChargeFW2/src/method.cpp:215:21: error: ‘const string’ {aka ‘const class std::__cxx11::basic_string<char>’} has no member named ‘ends_with’
if (method_name.ends_with(".so")) {
^~~~~~~~~
make[2]: *** [src/CMakeFiles/method.dir/build.make:76: src/CMakeFiles/method.dir/method.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:324: src/CMakeFiles/method.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Thanks
This method is included in the C++20 standard. What's your compiler version? GCC 9 or Clang 10 should be OK according to the https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_library_features.
Thanks, you are right. I'm using GCC 8.5. But nothing before prevent me to arrive until the compilation stage. Maybe this can be an issue. Best