簡體   English   中英

如何使用Makefile使用VTK庫編譯項目?

[英]How to compile project using VTK library using Makefile?

因此,我下載了C ++庫VTK,並在OSX環境的build子目錄中進行了本地構建。

我想使用帶有Makefile該庫(特別是我使用vtkSmartPointer類)來編譯項目。

例如,考慮以下源代碼:

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

對於Makefile我從第二個答案開始在這個職位給我交鋒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更改為-lvtkCommonCore 其他一些包含的庫似乎也是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM