How to compile project using VTK library using Makefile?

回眸只為那壹抹淺笑 提交于 2019-12-13 03:18:30

问题


For this reason I downloaded the C++ library VTK and made a local build in the build subdirectory on a OSX environment.

I would like to compile a project using this library (particularly I am using the class vtkSmartPointer) with Makefile.

Consider for example the following source code:

#include<iostream>
#include<vtkSmartPointer.h>
#include<vtkCallbackCommand.h>
int main()
{
  vtkSmartPointer<vtkCallbackCommand> keypressCallback =
    vtkSmartPointer<vtkCallbackCommand>::New();
  std::cout<<"hello world\n";
  return 0;
}

For the Makefile I started from the second answer in this post to which I aded VTK library path:

CXX = g++

# OpenCV trunk
CXXFLAGS = -std=c++11 \
    -I ../VTK/Common/Core/ -I ../VTK/build/Common/Core/ -I ../VTK/build/Utilities/KWIML/ \
    -I ../VTK/Utilities/KWIML/ \
    -L../VTK/build/lib \
    -lvtkCommon -lvtkFiltering -lvtkImaging -lvtkGraphics -lvtkGenericFiltering -lvtkIO

SOURCES := $(wildcard *.cpp)
OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
DEPENDS := $(patsubst %.cpp,%.d,$(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: parking

clean:
    $(RM) $(OBJECTS) $(DEPENDS) parking

# Linking the executable from the object files
parking: $(OBJECTS)
    $(CXX) $(WARNING) $(CXXFLAGS) $^ -o $@

-include $(DEPENDS)

%.o: %.cpp Makefile
    $(CXX) $(WARNING) $(CXXFLAGS) -MMD -MP -c $< -o $@

My environment variable DYLD_LIBRARY_PATH has the value ../cmake_bin_dir/instDir/lib:../VTK/build/lib/.

When I try to compile running make, I get the following error:

    ld: library not found for -lvtkCommon
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What part of the Makefile or program or step in the process is not correct?

Thank you in advance.


回答1:


The current VTK library does not contain libVtkCommon.so (see package contents section https://www.archlinux.org/packages/community/x86_64/vtk/). Are you looking for libVtkCommonCore.so? If that is the case you have to change -lvtkCommon to -lvtkCommonCore in your Makefile. The same seems to be the case for some of the other included libraries.



来源:https://stackoverflow.com/questions/52058232/how-to-compile-project-using-vtk-library-using-makefile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!