【问题标题】:How to compile project using VTK library using Makefile?如何使用 Makefile 使用 VTK 库编译项目?
【发布时间】:2018-08-28 12:43:12
【问题描述】:

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 或程序中的哪一部分或流程中的步骤不正确?

提前谢谢你。

【问题讨论】:

    标签: c++ makefile vtk


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      相关资源
      最近更新 更多