Magick ++没有连接OS Yosemite

时间:2015-08-04 03:30:11

标签: c++ macos gcc imagemagick

此问题已被提出:Magick++ not linking in OS X 10.8 没有决议。

这也是我之前提出的两个问题的后续问题,试图让c ++图像拼接算法正常工作(第二个问题是不必要的,我应该找到问题,但是,为了清楚起见)。 Using MTL/Boost Library Mac Terminal C++ :: "no such instruction" error when using gcc-4.9 on osx-yosemite

我的问题是我无法将imagemagick正确链接到我的gcc-4.9编译,如下所示:

$ 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

我已经尝试了magick page上建议的内容,此处列出的内容Undefined symbols for architecture x86_64以及其他一些内容。但是,唉,没有运气。

根据要求,makefile(来自我第一个链接上的原始项目,当前编辑)。

# $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

1 个答案:

答案 0 :(得分:0)

通常,我需要对clang ++以及要使用的标准库非常具体。

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

如果您计划移植到ImagickMagick 7,请将-Wno-deprecated-register添加到OPTFLAGS

要测试,请采取以下措施......

// 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;
}

编译&amp;链接...

clang++ -std=c++11 -stdlib=libstdc++ \
        `Magick++-config --cxxflags` \
        `Magick++-config --libs` \
        link_to_lib.cc -o link_to_lib