c++ - 如何使用Makefile使用VTK库编译项目?

标签 c++ makefile vtk

For this reason我下载了C++库VTK,并在OSX环境的build子目录中进行了本地构建。
我想使用此库(特别是我使用vtkSmartPointer类)和Makefile来编译项目。
例如,考虑以下源代码:

#include<iostream>
#include<vtkSmartPointer.h>
#include<vtkCallbackCommand.h>
int main()
{
  vtkSmartPointer<vtkCallbackCommand> keypressCallback =
    vtkSmartPointer<vtkCallbackCommand>::New();
  std::cout<<"hello world\n";
  return 0;
}
对于Makefile,我从this post中的第二个答案开始,我将VTK库路径添加到该答案中:
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 $@
我的环境变量DYLD_LIBRARY_PATH的值为../cmake_bin_dir/instDir/lib:../VTK/build/lib/
当我尝试编译正在运行的make时,出现以下错误:
    ld: library not found for -lvtkCommon
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile或程序中的哪个部分或过程中的哪个步骤不正确?
先感谢您。

最佳答案

当前的VTK库不包含libVtkCommon.so(请参阅软件包内容部分https://www.archlinux.org/packages/community/x86_64/vtk/)。您在寻找libVtkCommonCore.so吗?如果是这种情况,则必须在Makefile中将-lvtkCommon更改为-lvtkCommonCore。其他一些包含的库似乎也是如此。

关于c++ - 如何使用Makefile使用VTK库编译项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52058232/

相关文章:

C++ 虚拟析构函数从 std::vector 继承

c++ - SDL 自身和其他窗口崩溃

c++ - VTK 和 MPI : plot distributed data

python - 具有连接信息的 VTK 着色管过滤器

python - Mayavi 中的 TVTK 错误(Python)

c++ - VS2019 : Compiling Cap'nProto Crashes C++ Compiler

c++ - 将 C++ 中的字符串转换为大写

c - OpenMp和代码块16?

makefile - 强制 make 使用更具体的规则

c++ - 带有宏的 Makefile,不生成任何可执行文件