Home > Software design >  libvips in C on Mac
libvips in C on Mac

Time:07-09

I trying to write a program in CLion IDE that read a pdf file with C vips library and I get this error. What it's wrong?

Undefined symbols for architecture x86_64:
  "vips::VImage::pdfload(char const*, vips::VOption*)", referenced from:
      _main in main.cpp.o
  "vips::VImage::write_to_file(char const*, vips::VOption*) const", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My OS: Mac OS Monteray

My Code

#include <vips/vips8>

using namespace vips;
using namespace std;

int main() {

    VImage in =  VImage().pdfload("/Users/myuser/CLionProjects/untitled3/files/doc.pdf");
    in.write_to_file("/Users/myuser/CLionProjects/untitled3/output/img.jpeg");

}

CMakeList.txt

cmake_minimum_required(VERSION 3.19)
project(untitled5)

set(CMAKE_CXX_STANDARD 11)

find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_search_module(VIPS REQUIRED vips)

include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
include_directories(${VIPS_INCLUDE_DIRS})
link_directories(${VIPS_LIBRARY_DIRS})

add_executable(untitled5 main.cpp)

add_definitions(${GLIB_CFLAGS_OTHER})
target_link_libraries(untitled5 ${GLIB_LIBRARIES})
target_link_libraries(untitled5 ${VIPS_LIBRARIES})

CodePudding user response:

The missing libraries libvips-cpp to link to.

# pkg_search_module(VIPS REQUIRED vips)
pkg_search_module(VIPS REQUIRED vips-cpp)

pkg_search_module(GLIB REQUIRED glib-2.0) can be removed, vips-cpp provides it in the libs

$ pkg-config --libs vips-cpp
-L/usr/local/lib -lvips-cpp -lvips -lgobject-2.0 -lglib-2.0
  • Related