-1

I'm trying to add function iceemdan() to the open source library libeemd.c. I'm trying to debug it with an IDE. The make file's first call to clang result's in clang's inability to find the gsl library, even though it is present and the make file upon which the IDE's make file is based has no trouble linking to gsl.

Here's the make file output (gsl errors and context only) using the Codelite IDE make file:

Executing Pre Build commands ...
Done
make[1]: Leaving directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
make[1]: Entering directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
clang -o ./Debug/iceemdan-clang @"iceemdan-clang.txt" -L.   
Undefined symbols for architecture x86_64:
  "_gsl_linalg_solve_tridiag", referenced from:
    _emd_evaluate_spline in main.c.o
  "_gsl_poly_dd_eval", referenced from:
    _emd_evaluate_spline in main.c.o
  "_gsl_poly_dd_init", referenced from:
    _emd_evaluate_spline in main.c.o
  "_gsl_ran_gaussian", referenced from:
    _iceemdan in main.c.o
    _eemd in main.c.o
    _ceemdan in main.c.o
  "_gsl_rng_alloc", referenced from:
    _allocate_eemd_workspace in main.c.o
  "_gsl_rng_free", referenced from:
    _free_eemd_workspace in main.c.o
  "_gsl_rng_mt19937", referenced from:
    _allocate_eemd_workspace in main.c.o
  "_gsl_rng_set", referenced from:
    _set_rng_seed in main.c.o
  "_gsl_set_error_handler_off", referenced from:
    _iceemdan in main.c.o
    _eemd in main.c.o
    _ceemdan in main.c.o
      _emd_evaluate_spline in main.c.o
  "_gsl_sf_sin", referenced from:
      _main in main.c.o
  "_gsl_stats_sd", referenced from:
      _iceemdan in main.c.o
      _eemd in main.c.o
      _ceemdan in main.c.o
  "_gsl_strerror", referenced from:
      _emd_evaluate_spline in main.c.o
  "_gsl_vector_view_array", referenced from:
      _emd_evaluate_spline in main.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [iceemdan-clang.mk:82: Debug/iceemdan-clang] Error 1
make[1]: Leaving directory '/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang'
make: *** [Makefile:5: All] Error 2

This make file, a modification of the package make file to run on the Mac, works:

.PHONY: all clean install uninstall

version := 1.4.1
gsl_flags := $(shell pkg-config --libs --cflags gsl)
ifeq ($(gsl_flags),)
$(error Failed to query GSL complilation flags from pkg-config)
endif
gsl_flags += -DHAVE_INLINE
commonflags := -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith
commonflags += $(CFLAGS)
commonflags += -g -DEEMD_DEBUG=0
#commonflags += -fopenmp
commonflags += -DCLANG
PREFIX ?= /usr

SONAME = -soname
ifeq ($(shell uname -s),Darwin)
    SONAME = -install_name
endif

define uninstall_msg
If you used $(PREFIX) as the prefix when running `make install`,
you can undo the install by removing these files:
$(PREFIX)/include/eemd.h
$(PREFIX)/lib/libeemd.a
$(PREFIX)/lib/libeemd.so
$(PREFIX)/lib/libeemd.so.$(version)
endef
export uninstall_msg

all: libeemd.so.$(version) libeemd.a eemd.h

clean:
    rm -f libeemd.so libeemd.so.$(version) libeemd.a eemd.h obj/eemd.o
    rm -rf obj

install:
    install -d $(PREFIX)/include
    install -d $(PREFIX)/lib
    install -m644 eemd.h $(PREFIX)/include
    install -m644 libeemd.a $(PREFIX)/lib
    install libeemd.so.$(version) $(PREFIX)/lib
    cp -Pf libeemd.so $(PREFIX)/lib

uninstall:
    @echo "$$uninstall_msg"

obj:
    mkdir -p obj

obj/eemd.o: src/eemd.c src/eemd.h | obj
    clang $(commonflags) -c $< $(gsl_flags) -o $@

libeemd.a: obj/eemd.o
    $(AR) rcs $@ $^

libeemd.so.$(version): src/eemd.c src/eemd.h
    clang $(commonflags) $< -fPIC -shared -Wl,$(SONAME),$@ $(gsl_flags) -o $@
    ln -sf $@ libeemd.so

eemd.h: src/eemd.h
    cp $< $@

The Codelite second level make file is here. (The first level merely calls it.) I'm running in a different directory to avoid overwriting my good code.

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased      
##
## Debug
ProjectName            :=iceemdan-clang
ConfigurationName      :=Debug
WorkspacePath          :=/Users/Common/iceemdan-dev/iceemdan-dev
ProjectPath            :=/Users/Common/iceemdan-dev/iceemdan-dev/iceemdan-clang
IntermediateDirectory  :=./Debug
OutDir                 := $(IntermediateDirectory)
CurrentFileName        :=
CurrentFilePath        :=
CurrentFileFullPath    :=
User                   :=Coleman Family
Date                   :=08/08/2018
CodeLitePath           :="/Users/Common/Library/Application Support/CodeLite"
LinkerName             :=clang
SharedObjectLinkerName :=clang -shared -fPIC
ObjectSuffix           :=.o
DependSuffix           :=
PreprocessSuffix       :=.o.i
DebugSwitch            :=-gstab
IncludeSwitch          :=-I
LibrarySwitch          :=-l
OutputSwitch           :=-o 
LibraryPathSwitch      :=-L
PreprocessorSwitch     :=-D
SourceSwitch           :=-c 
OutputFile             :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors          :=
ObjectSwitch           :=-o 
ArchiveOutputSwitch    := 
PreprocessOnlySwitch   :=-E 
ObjectsFileList        :="iceemdan-clang.txt"
PCHCompileFlags        :=
MakeDirCommand         :=mkdir -p
LinkOptions            :=  
IncludePath            :=  $(IncludeSwitch). $(IncludeSwitch). 
IncludePCH             := 
RcIncludePath          := 
Libs                   := 
ArLibs                 :=  
LibPath                := $(LibraryPathSwitch). 

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR       := ar rcus
CXX      := clang++
CC       := clang
CXXFLAGS :=  -g -O0 -Wall $(Preprocessors)
CFLAGS   :=  $(commonflags) $< -fPIC -shared -Wl $@ $(gsl_flags) -o $@ $(Preprocessors)
ASFLAGS  := 
AS       := llvm-as


##
## User defined environment variables
##
CodeLiteDir:=/Applications/codelite.app/Contents/SharedSupport/
PATH:=/Users/Common/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/opt/local/include
Srcs=main.c 

Objects0=$(IntermediateDirectory)/main.c$(ObjectSuffix) 



Objects=$(Objects0) 

##
## Main Build Targets 
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects) 
    @$(MakeDirCommand) $(@D)
    @echo "" > $(IntermediateDirectory)/.d
    @echo $(Objects0)  > $(ObjectsFileList)
    $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
    @test -d ./Debug || $(MakeDirCommand) ./Debug


$(IntermediateDirectory)/.d:
    @test -d ./Debug || $(MakeDirCommand) ./Debug

PreBuild:
    @echo Executing Pre Build commands ...
    $(eval gsl_flags = -L/opt/local/lib -lgsl -lgslcblas -lm -I/opt/local/include -DHAVE_INLINE)
    $(eval commonflags := -Wall -Wextra -std=c99 -pedantic -Wno-unknown-pragmas -Wshadow -Wpointer-arith)
    $(eval commonflags += $(CFLAGS))
    $(eval commonflags += -g -DEEMD_DEBUG=0)
    $(eval commonflags += -DCLANG)
    $(eval PREFIX ?= /usr)
    @echo Done

# all

Debug/main.c.o: main.c 
#src/eemd.h | Debug
    clang $(commonflags) -c $< $(gsl_flags) -o $@

Debug/main.c.a: Debug/main.c.o
    $(AR) rcs $@ $^

eemd: main.c src/eemd.h
    clang $(commonflags) $< -fPIC -shared -Wl, ,$@ $(gsl_flags) -o $@

My apologies for the length of this post. In the past, I've only run unmodified make files, not debug them. So, a lot of this is new and not transparent to me. I'd appreciate any help.

Chuck
  • 1
  • 3

1 Answers1

0

I had to trick the command for building main.c.o using global variables.

Chuck
  • 1
  • 3