1

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.

Community
  • 1
  • 1
roschach
  • 8,390
  • 14
  • 74
  • 124

1 Answers1

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.

Stefan Scheller
  • 953
  • 1
  • 12
  • 22