I would like to use Open3d in LAMMPS. Open3D details how to find the pre-installed Open3D package using cmake.
Using the above, I have written a cmake file that I believe LAMMPS uses during its build stage to find packages and link them. Curiously, the line
target_link_libraries(lammps PRIVATE Open3D::Open3D)
appears to cause the compiler to find errors in the LAMMPS src code, i.e.,
/home/USER/lammps/src/fmtlib_format.cpp:58:51: error: duplicate explicit instantiation of ‘struct fmt::v7_lmp::detail::basic_data<void>’ [-fpermissive]
58 | template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
If I comment the target_link_libraries statement, the code compiles just fine (but doesn't link to Open3D). Apologies for being unable to provide a MWE as I do not know how to replicate this behaviour in a simple manner. Could you please explain to me why the target_link_libraries command causes the compiler to find errors in the LAMMPS src code and provide a solution to prevent this from occuring? If relevant I am using Clion 2021.1.2 and
CMAKE_CXX_COMPILER_VERSION = 9.3.0
CMAKE_CXX_STANDARD = 11
CMAKE_VERSION = 3.19.2
Related
So I am trying to compile this flip fluids addon with blender, so I followed this tutorial, https://www.youtube.com/watch?v=TVKM1egDoGs , So I first ran cmake.exe -G "MinGW Makefiles" .. and it was telling me that it was missing a CMakeLists File... So I added one... then I ran cmake.exe --build . and it got to 3 percent than showed me errors like ...
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:29,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/mutex:93:9: note: previous definition of 'class std::recursive_mutex'
class recursive_mutex : private __recursive_mutex_base
^~~~~~~~~~~~~~~
In file included from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.condition_variable.h:25,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/threadutils.h:31,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshlevelset.h:65,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/meshobject.h:30,
from C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/fluidsimulation.h:38,
from C:\Users\N\Downloads\Blender-FLIP-Fluids-master\src\engine\c_bindings\fluidsimulation_c.cpp:25:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.mutex.h:142:44: error: conflicting declaration 'typedef class std::_NonRecursive<std::recursive_mutex> std::mutex'
This is the full error https://pastebin.com/KTnALG1E, where is this coming from?? is it a mingw error or what? Can someone help please?
Your full error message includes a more interesting bit:
C:/Users/N/Downloads/Blender-FLIP-Fluids-master/src/engine/mingw32_threads/mingw.thread.h:32:2:
error: #error This version of MinGW seems to include a win32 port of
pthreads, and probably already has C++11 std threading classes
implemented, based on pthreads. It is likely that you will get class
redefinition errors below, and unfortunately this implementation can
not be used standalone and independent of the system header,
since it relies on it for std::unique_lock and other utility classes.
If you would still like to use this implementation (as it is more
lightweight), you have to edit the c++-config.h system header of your
MinGW to not define _GLIBCXX_HAS_GTHREADS. This will prevent system
headers from defining actual threading classes while still defining
the necessary utility classes.
So either install a different version of mingw or edit your mingw files according to the instructions above.
My Dockerfile uses FROM gcc:5, runs apt-get update and installs CMake v3.9 via wget. My top-level CMakeLists.txt has set(CMAKE_CXX_STANDARD 11) but that doesn't seem to convince gcc to compile using C++11 as I get the following error:
/ifeature.hpp:51:42: error: 'shared_ptr' in namespace 'std' does not name a template type
virtual float compare(const std::shared_ptr<IFeature>& feature) const = 0
^
I tried adding variations of set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") with libstdc++, gnuc++11 etc. but the compiler does not recognize them. I also tried add_compile_options(-std=c++11) to no avail. I also tried apt-get upgrade gcc but that didn't help either.
What am I missing here?
For future reference and in the interest of anyone who may encounter this page, I should update that just as #some-programmer-dude mentioned in the comment, simply including <memory> resolved the error shown in my question.
Given that my original development environment was different from the one in my Docker image and the code was written with different compiler, I had to resolve a few similar issues (missing include files) to satisfy gcc-v5 requirements.
CMake is giving me a real hard time, here. I checked out llvm, clang, and extras, and I created a custom driver folder, added it to the llvm\tools\clang\tools\extra\CMakeLists.txt and created my own CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
set(LLVM_LINK_COMPONENTS
Support
)
set(CMAKE_CXX_FLAGS ${LLVM_CONFIG})
set(CMAKE_CXX_COMPILER "clang++")
add_clang_executable(mydriver
main.cpp
)
set(CLANG_LIBS clangFrontend clangDriver clangSerialization clangParse
clangCodeGen clangSema clangAnalysis clangEdit clangAST clangLex
clangBasic )
target_link_libraries(mydriver ${CLANG_LIBS})
target_link_libraries(mydriver ${LLVM_LIBS})
CMake works fine. I target VS2017 and build the mydriver project with msbuild
λ msbuild tools\clang\tools\extra\mydriver\mydriver.vcxproj
This results in the following error:
"C:\dev\llvm-build\tools\clang\tools\extra\mydriver\mydriver.vcxproj" (default target) (1) ->
(ClCompile target) ->
C:\dev\llvm\tools\clang\tools\extra\mydriver\main.cpp(45): error C2027: use of undefined type 'clang::Preprocessor Options' [C:\dev\llvm-build\tools\clang\tools\extra\mydriver\mydriver.vcxproj]
C:\dev\llvm\tools\clang\tools\extra\mydriver\main.cpp(45): error C2228: left of '.addRemappedFile' must have class /struct/union [C:\dev\llvm-build\tools\clang\tools\extra\mydriver\mydriver.vcxproj]
C:\dev\llvm\tools\clang\tools\extra\mydriver\main.cpp(50): error C2664: 'void clang::CompilerInstance::setInvocati on(std::shared_ptr<clang::CompilerInvocation>)': cannot convert argument 1 from 'clang::CompilerInvocation *' to 'st d::shared_ptr<clang::CompilerInvocation>' [C:\dev\llvm-build\tools\clang\tools\extra\mydriver\mydriver.vcxproj]
However, clangLex is clearly included in the CLANG_LIBS variable in my CMakeLists.txt. The documentation of the clang::PreprocessorOptions class seems to indicate that I have the right libs included.
Any ideas?
Please note that this question is closely related to this one:
Generate assembly from C code in memory using libclang
In classic SO fashion, the problem was that the include file had migrated since the example was posted. The clang documentation requires a new header file, that is, in fact, in the include path. All I needed was:
#include <clang/Lex/PreprocessorOptions.h>
Sorry folks, nothing to see here.
I'm trying to run the example "Scale_Space_Surface_Reconstruction_3" from CGAL library on CodeBlocks IDE on Ubuntu platform, as it would be nice
to have the IDE support for code completion and a more automatic configuration process.
I managed to successfully execute it by compiling it with cmake on the terminal window.
However, on CodeBlocks, after creating a new project and copying the code from the example, I get the following error:
/usr/local/include/CGAL/Scale_Space_Reconstruction_3/Scale_Space_Surface_Reconstruction_Impl_3.h:165:23: error: variable or field 'pca' declared void
Approximation pca( _nn[i]);
By looking inside the code, I found out that this is due to an undefined Macro CGAL_EIGEN3_ENABLED. As my experiment shows, if I define the macro at
pre-processing time, I do not get the same error. That is because, by defining the macro, the type definition Default::Get< wA,void>::type, becomes
Default::Get< wA, Weighted_PCA_approximation_3<Gt>>::type, and the compiler does not complain any more.
Unfortunately, as a deserved prize for messing with things I do not really understand, I get a segmentation fault at runtime.
How should I change the compiler options of codeBlocks to make the compilation succeed, and the executable run successfully?
I have the following include paths:
/usr/local/lib/CGAL/ /usr/local/include /usr/include /usr/include/eigen3.
I also included the following libraries:
libCGAL.so, libCGAL_Core.so, libCGAL_ImageIO.so, libgmp.so, libmpfr.so, libtbb.so, libtbbmalloc.so, libtbbmalloc_proxy.so
First of all I am complete new to C++, so if you know the answer please be patient with me ;). Here my problem:
I wanna solve an IP with Gurobi in a C++ Code. The Code itself seems fine since there are no expression marked as errors. However when I run the Code I get the following error report:
Undefined symbols for architecture x86_64:
and many lines like that:
"GRBLinExpr::GRBLinExpr(GRBVar, double)", referenced from:
bridge_problem::max_flow_lp(time_expanded_network&, lemon::ListDigraph&, lemon::DigraphExtender<lemon::ListDigraphBase>::ArcMap<int>&, lemon::DigraphExtender<lemon::ListDigraphBase>::ArcMap<int>&, lemon::DigraphExtender<lemon::ListDigraphBase>::NodeMap<int>&) in bridge_problem.cpp.o
I suppose that the mistake is in my CMakeList.txt file. This file was automatically created since I am using Clion and for including gurobi I entered those additional lines:
include_directories(/Library/gurobi604/mac64/include)
link_directories(/Library/gurobi604/mac64/lib/libgurobi_c++.a)
link_directories(/Library/gurobi604/mac64/lib/libgurobi60.so)
Any help is greatly appreciated and if you need any more information just let me know. (In case it is important I using a mac).
EDIT: I changed my make code since I found this one:
https://github.com/joschu/trajopt/blob/master/cmake/modules/FindGUROBI.cmake
I changed the version since I have gurobi604 but it still does not work. My new error message is:
fatal error: 'gurobi_c++.h' file not found #include "gurobi_c++.h"
I don't get it since I thought by
find_path(GUROBI_INCLUDE_DIR
NAMES gurobi_c++.h
PATHS "$ENV{GUROBI_HOME}/include"
"/Library/gurobi604/mac64/include"
"C:\\libs\\gurobi604\\include"
)
that should be easy to find. Any suggestion?
From the small excerpt of your CMakeLists.txt, I expect you should be using target_link_libraries rather than link_directories.
I'd normally recommend linking to the static version of any library rather than the shared if possible (i.e. in this case prefer "libgurobi_c++.a" over "libgurobi60.so" assuming they're the same library, just compiled differently).
So, if your exe is called MyExe, you could do:
target_link_libraries(MyExe /Library/gurobi604/mac64/lib/libgurobi_c++.a)
Also, it's almost always best to avoid specifying hard-coded paths in your CMakeLists.txt. Although your copy of "libgurobi_c++.a" lives in "/Library/gurobi604/mac64/lib/", that won't be the case for other users, or on different platforms.
You can avoid this by having CMake "find" the library, for example by calling find_library:
find_library(Gurobi NAMES gurobi_c++)
if(NOT Gurobi)
message(FATAL_ERROR "Failed to find Gurobi lib. Try setting CMAKE_PREFIX_PATH")
endif()
target_link_libraries(MyExe ${Gurobi})
Then, when you run CMake, you just need to tell it where the Gurobi library is. I'm not sure how you do that in CLion, but for example if you were running CMake from the command line, you'd do:
cmake . -DCMAKE_PREFIX_PATH=/Library/gurobi604/mac64