flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.42k stars 417 forks source link

Linker errors #232

Open harshmdeshpande opened 7 years ago

harshmdeshpande commented 7 years ago

I know this question has been asked many times, but the solutions discussed doesn't seem to solve it. Also it doesn't help that I am new to writing CMakeLists.txt

So I have compiled ´libccd´ with the following command: cmake -G "Unix Makefiles" -DENABLE_DOUBLE_PRECISION=ON -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=ON ..

Then I compiled fcl with simply cmake ..

Next, my CMakeLists.txt looks like this:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
cmake_minimum_required(VERSION 2.6)

project(fcl_test)

add_executable(hello_fcl src/hello_fcl.cpp)

find_package(fcl REQUIRED)

if (fcl_FOUND)
  message("fcl found!")
  include_directories(${fcl_INCLUDE_DIRS})
endif (fcl_FOUND) 

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(Eigen3 REQUIRED)

if (EIGEN3_FOUND)
  message("eigen found!")
  include_directories(${EIGEN3_INCLUDE_DIR})
endif (EIGEN3_FOUND) 

target_link_libraries(hello_fcl ${fcl_LIBRARIES})

In libccd, compiler.h looks like this:

/**
 * Marks exported function.
 */
#ifdef _WIN32
# ifdef ccd_EXPORTS
#   define _ccd_export __declspec(dllexport)
# else /* ccd_EXPORTS */
#   define _ccd_export __declspec(dllimport)
# endif /* ccd_EXPORTS */
#else /* _WIN32 */
# define _ccd_export
#endif /* _WIN32 */

vec3.h

/**
 * Holds origin (0,0,0) - this variable is meant to be read-only!
 */
//extern ccd_vec3_t *ccd_vec3_origin;
_ccd_export extern ccd_vec3_t *ccd_vec3_origin;

support.h

/**
 * Computes support point of obj1 and obj2 in direction dir.
 * Support point is returned via supp.
 */
_ccd_export void __ccdSupport(const void *obj1, const void *obj2,
                  const ccd_vec3_t *dir, const ccd_t *ccd,
                  ccd_support_t *supp);

Still I get undefined reference errors:

undefined reference to `ccdVec3PointTriDist2'
undefined reference to `ccd_vec3_origin'
undefined reference to `__ccdSupport'
undefined reference to `ccdPtAddVertex'
undefined reference to `ccdPtAddEdge'

I am using Ubuntu14.04

Edit: The tests are compiled successfully and they pass when I execute them.

harshmdeshpande commented 7 years ago

I added the following lines in the CMakeLIsts.txt:

find_package(CCD REQUIRED)
include_directories(${CCD_INCLUDE_DIRS})
target_link_libraries(hello_fcl ${fcl_LIBRARIES} ${CCD_LIBRARIES})

This solved the earlier problem.

Now my code looks like this:

#include <fcl/fcl.h>
#include <fcl/math/triangle.h>
#include <fcl/geometry/bvh/BVH_model-inl.h>
#include <fcl/math/bv/OBBRSS.h>

int main() {
    std::vector<fcl::Vector3<double>> vertices;
    std::vector<fcl::Triangle> triangles;

    typedef fcl::BVHModel<fcl::OBBRSS<double>> Model;
    Model *model = new Model();
    model->beginModel();
    model->addSubModel(vertices, triangles);

    return 0;
}

But now I get linker errors like:

undefined reference to `fcl::CollisionGeometry<double>::CollisionGeometry()'
undefined reference to `fcl::Triangle::Triangle()'
undefined reference to `fcl::AABB<double>::AABB()'
harshmdeshpande commented 7 years ago

Solved it with target_link_libraries(hello_fcl fcl ${CCD_LIBRARIES}