0

This question has already been asked: Magick++ not linking in OS X 10.8 without a resolution.

This is also a follow-on from two previous questions I've asked in an attempt to get a c++ image-stitching algorithm to work properly (the second question was unnecessary, I should have found the issue, but, for clarity). Using MTL/Boost Library Mac Terminal C++ :: "no such instruction" error when using gcc-4.9 on osx-yosemite

My issue is that I cannot properly link imagemagick to my gcc-4.9 compile, as follows:

$ make
Linking ...
Undefined symbols for architecture x86_64:
  "Magick::Image::write(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
  FileRender::finish()      in main.o
  "Magick::Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      planet(char const*) in main.o
      work(int, char**) in main.o
      test_transform(char const*, char const*) in main.o
      test_warp(int, char**) in main.o
      gallery(char const*, char const*) in main.o
      test_extrema(char const*) in main.o
      test_feature(char const*, int) in main.o
      ...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [image-stitching] Error 1

I've tried what is suggested on the magick page, what is listed here Undefined symbols for architecture x86_64, and quite a bit of others. But, alas, no luck.

As requested, the makefile (from the original project on my first link, with current edits).

# $File: Makefile
# $Date: Wed Jun 17 20:52:38 2015 +0800

OBJ_DIR = obj
TARGET = image-stitching

INCLUDE_DIR = -Iinclude -I/usr/local/include
DEFINES = -DDEBUG

OPTFLAGS = -O3 -Wall -Wextra

LIBS =
#INCLUDE_DIR += $(shell pkg-config --cflags $(LIBS))

CXXFLAGS = $(INCLUDE_DIR) -fopenmp
CXXFLAGS += $(DEFINES) -std=c++11 $(OPTFLAGS)
CXXFLAGS += $(shell Magick++-config --cxxflags)

LDFLAGS = -fopenmp $(OPTFLAGS)
#LDFLAGS += $(shell pkg-config $(LIBS) --libs)
LDFLAGS += $(shell Magick++-config --ldflags --libs)
LDFLAGS += -L/usr/local/Cellar/libpng/1.6.18/lib
#LDFLAGS += -lImageMagick

CC = g++-4.9
SHELL = bash
ccSOURCES = $(shell find -name "*.cc" | sed 's/^\.\///g')
OBJS = $(addprefix $(OBJ_DIR)/,$(ccSOURCES:.cc=.o))
DEPFILES = $(OBJS:.o=.d)

.PHONY: all clean run

all: $(TARGET)

ifneq ($(MAKECMDGOALS), clean)
sinclude $(DEPFILES)
endif

    $(OBJ_DIR)/%.o: %.cc
        @echo "[cc] $< ..."
        @$(CC) -c $< -o $@ $(CXXFLAGS)

    $(OBJ_DIR)/%.d: %.cc  Makefile
        @mkdir -p $(dir $@)
        @echo "[dep] $< ..."
        @$(CC) $(CXXFLAGS) $(DEFINES) -MM -MT "$(OBJ_DIR)/$(<:.cc=.o)      $(OBJ_DIR)/$(<:.cc=.d)" "$<"  > "$@"


$(TARGET): $(OBJS)
    @echo "Linking ..."
    @$(CC) $(OBJS) -o $@ $(LDFLAGS)
    @echo "done."


clean:
    @rm -rvf $(OBJ_DIR)

run: $(TARGET)
    ./$(TARGET) lenna.png lenna_r.png
Community
  • 1
  • 1
Meshach
  • 315
  • 1
  • 2
  • 16
  • You need to provide your Makefile, or at least the linker commandline that fails. – Mark Setchell Aug 04 '15 at 05:59
  • @MarkSetchell Done, let me know if there's something else I can provide to help. – Meshach Aug 04 '15 at 07:46
  • Your `$(shell find -name...)` looks wrong... normally you must provide a starting path, like `find . -name ...` or `find $HOME -name ...` – Mark Setchell Aug 04 '15 at 09:52
  • What is the output of `Magick++-config --ldflags --libs` when executed from *inside* the Makefile - it maybe different outside the Makefile as a result of your `PATH`... – Mark Setchell Aug 04 '15 at 10:10
  • @MarkSetchell Not entirely sure how to echo just that Magick++ line, suggestions? Something like `PHONY: all all: ; $(info $$var is [${var}])` – Meshach Aug 04 '15 at 18:44

1 Answers1

0

Usually, I need to be very specific about clang++, and which standard library to use.

# Switch GCC for clang
CC=clang
# Switch g++ for clang++
CXXS=clang++
# Ensure stdlib is defined
CXXFLAGS += $(DEFINES) -std=gnu++11 -stdlib=libstdc++ $(OPTFLAGS)

If you plan on porting to ImagickMagick 7, add -Wno-deprecated-register to OPTFLAGS

To test, take the following...

// link_to_lib.cc
#include <iostream>
#include <Magick++.h>

using namespace std;
using namespace Magick;

int main(int argc, const char ** argv) {
    InitializeMagick(*argv);
    Image img("rose:");
    Geometry size = img.size();
    cout << size.width() << "x" << size.height() << endl;
    return 0;
}

And compile & link with...

clang++ -std=c++11 -stdlib=libstdc++ \
        `Magick++-config --cxxflags` \
        `Magick++-config --libs` \
        link_to_lib.cc -o link_to_lib
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • If I use clang as my cc, then I get the "ld: library not found for -lgomp" error. – Meshach Aug 04 '15 at 18:36
  • @Meshach are you mixing [Clang/OpenMP](https://clang-omp.github.io) & [Gnu-OpenMP](https://gcc.gnu.org/projects/gomp/) features? – emcconville Aug 04 '15 at 18:52
  • It appears this project may have interlaced features. However, to be precise, I'm attempting to run [this](https://github.com/ppwwyyxx/panorama) project on a modern mac. – Meshach Aug 04 '15 at 19:18
  • Ah, so you need to port that project to OS X, as some features are not supported. Luckily [boost shared_ptr](http://www.boost.org/doc/libs/1_58_0/libs/smart_ptr/shared_ptr.htm) library will simplify everything. – emcconville Aug 05 '15 at 13:52
  • I'm not sure if you've had the chance to peruse the code from that project at all, but in main.cc, he uses imgptr extensively, are you suggested I cull that and replace it with the shared_ptr class? (I'm hoping this issue is localized to the main.) – Meshach Aug 05 '15 at 19:53