How to solve gfortran compilation and linking error? - fortran

I have trying to compile a collection of old fortran and C codes with gfortran. They compile fine on a linux workstation but this fails in a Mac. Any idea on how to solve this ? The Makefile in the Linux version has one extra flag in CFLAGS and FFLAGS -mcmodel=large that I removed following some advice.
This is the error at the final linking line.
gfortran -fopenmp -O3 -m64 lsmrDataModule.o lsmrModule.o delsph.o gaussian.o CalSurfG2.o main2.o aprod.o cluster1.o covar.o datum.o delaz.o delaz2.o direct1.o dist.o exist.o freeunit.o ifindi.o indexxi.o juliam.o matmult1.o matmult2.o matmult3.o mdian1.o normlz.o ran.o redist.o resstat_FDD.o scopy.o sdc2.o setorg.o snrm2.o sort.o sorti.o sscal.o svd.o tiddid.o trialsrc_FDD_shot.o trimlen.o vmodel.o RaySPDR2new.o getinpSPDR.o getdata_SPDR.o dtres_FDD_lm5.o weighting_FDD.o lsfitHFDD_lsqr_lm5.o get_dims.o add_sta.o find_id2.o surfdisp96.o atoangle_.o atoangle.o datetime_.o hypot_.o rpad_.o sscanf3_.o transform_r_gfortran_double.o -o tomoJointBS
final section layout:
__TEXT/__text addr=0x1000014A0, size=0x0008F7D1, fileOffset=0x000014A0, type=1
__TEXT/__text_startup addr=0x100090C80, size=0x00000026, fileOffset=0x00090C80, type=1
__TEXT/__stubs addr=0x100090CA6, size=0x0000018C, fileOffset=0x00090CA6, type=28
__TEXT/__stub_helper addr=0x100090E34, size=0x000002A4, fileOffset=0x00090E34, type=32
__TEXT/__cstring addr=0x1000910D8, size=0x000130B9, fileOffset=0x000910D8, type=13
__TEXT/__const addr=0x1000A41A0, size=0x00004C6C, fileOffset=0x000A41A0, type=0
__TEXT/__eh_frame addr=0x1000A8E10, size=0x000051E0, fileOffset=0x000A8E10, type=19
__DATA/__got addr=0x1000AE000, size=0x00000028, fileOffset=0x000AE000, type=29
__DATA/__nl_symbol_ptr addr=0x1000AE028, size=0x00000010, fileOffset=0x000AE028, type=29
__DATA/__la_symbol_ptr addr=0x1000AE038, size=0x00000210, fileOffset=0x000AE038, type=27
__DATA/__const addr=0x1000AE248, size=0x00000010, fileOffset=0x000AE248, type=0
__DATA/__data addr=0x1000AE260, size=0x00000030, fileOffset=0x000AE260, type=0
__DATA/__pu_bss2 addr=0x1000AE290, size=0x000000A8, fileOffset=0x00000000, type=25
__DATA/__pu_bss5 addr=0x1000AE340, size=0x000004C0, fileOffset=0x00000000, type=25
__DATA/__bss5 addr=0x1000AE800, size=0x00229680, fileOffset=0x00000000, type=25
__DATA/__pu_bss3 addr=0x1002D7E80, size=0x00000028, fileOffset=0x00000000, type=25
__DATA/__common addr=0x1002D7EC0, size=0x000000A0, fileOffset=0x00000000, type=25
__DATA/__bss3 addr=0x1002D7F60, size=0x00000010, fileOffset=0x00000000, type=25
__DATA/__bss2 addr=0x1002D7F70, size=0x00000004, fileOffset=0x00000000, type=25
__DATA/__huge addr=0x1002D7F80, size=0x3FA6069F4, fileOffset=0x00000000, type=25
ld: unexpected bindingNone in '_MAIN__' from main2.o for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [tomoJointBS] Error 1
This is the Makefile.
CMD = tomoJointBS
CC = gcc
FC = gfortran
SRCS = main2.f\
aprod.f cluster1.f covar.f datum.f \
delaz.f delaz2.f direct1.f dist.f exist.f \
freeunit.f ifindi.f \
indexxi.f juliam.f \
matmult1.f matmult2.f matmult3.f mdian1.f \
normlz.f ran.f redist.f \
resstat_FDD.f scopy.f sdc2.f setorg.f \
snrm2.f sort.f sorti.f sscal.f \
svd.f tiddid.f trialsrc_FDD_shot.f trimlen.f \
vmodel.f RaySPDR2new.f \
getinpSPDR.f getdata_SPDR.f \
dtres_FDD_lm5.f weighting_FDD.f lsfitHFDD_lsqr_lm5.f \
get_dims.f add_sta.f find_id2.f \
surfdisp96.f
CSRCS = atoangle_.c atoangle.c datetime_.c hypot_.c rpad_.c \
sscanf3_.c transform_r_gfortran_double.c
F90SRCS = lsmrDataModule.f90 \
lsmrModule.f90 delsph.f90 gaussian.f90
OBJS = $(F90SRCS:%.f90=%.o) CalSurfG2.o $(SRCS:%.f=%.o) $(CSRCS:%.c=%.o)
INCLDIR = ./include
CFLAGS = -O3 -I$(INCLDIR) -m64
FFLAGS = -O3 -I$(INCLDIR) -ffixed-line-length-none -ffloat-store -W -m64 -fbounds-check
LDFLAGS = -O3 -m64
all: $(CMD)
$(CMD): $(OBJS)
$(FC) -fopenmp $(LDFLAGS) $(OBJS) $(LIBS) -o $#
%.o: %.f90
$(FC) $(FFLAGS) -c $(#F:.o=.f90) -o $#
CalSurfG2.o:CalSurfGnew2.f90
$(FC) -fopenmp $(FFLAGS) -c $< -o $#
%.o: %.f
$(FC) $(FFLAGS) -c $(#F:.o=.f) -o $#

Related

function define in .h declared in .cu

I made a project split in three folders : src, include, obj
I am using CImg.h and cuda.h library.
I declare void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &);in convolve.h
and define it in convolve.cu
my files :
main.cpp :
#include "CImg.h"
#include "../include/convolve.h"
using namespace cimg_library;
int main(){
CImg<float> var1("/*path*/");
CImg<float> var2("/*path2*/");
convolve(var1,var2);
//some code
}
convolve.h :
1 #ifndef CONVOLVE_H
2 #define CONVOLVE_H
//some define
10 void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &);
11 #endif //CONVOLVE_H
convolve.cu :
1 void convolve(CImg<float>& img, const CImg<float>& kernel){
//some code
24 kernel<<<dimGrid,dimBlocks>>>(/*some arg*/);
}
and my new makefile :
1 CC=nvcc
2 CX=g++
3 IDIR =../include
4 special_IDIR = /usr/local/cuda-9.0/include
5 LDIR = /usr/local/cuda-9.0/lib64
6 CFLAGS=-I$(special_IDIR) -L$(LDIR)
7
8 LIBS = -lX11 -lpthread -lcudart
9 ODIR = ../obj
10
11
12 _DEPS = convolve.h kernel.cuh
13 DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
14
15 _OBJ = main.o convolve.o kernel.o
16 OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
17
18 $(ODIR)/%.o: %.cpp $(DEPS)
19 $(CX) -x c++ -o $# $< $(CFLAGS) $(LIBS)
20
21 $(ODIR)/%.o: %.cu $(DEPS)
22 $(CC) -cu -o $# $< $(CFLAGS)
23
24 all: $(OBJ)
25 $(CC) -o $# $^ $(CFLAGS)
26
27
28 .PHONY: clean
29
30 clean:
31 rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
Here is my issue : it says the reference to void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &) is undefined.
I think this is because I never clearly say to the compiler that the definition of convolve is in convolve.cu. But I do not find how to make this link properly.
Thanks for your help !
please don't post code (or Makefile contents) with line numbers. It just gets in the way, usually.
The compilation process here follows a compile...link process. The first stage is the compile stage, and you should be using -c for both g++ and nvcc during this stage (i.e. for both types of Makefile targets)
nvcc has no -cu option. I think maybe you meant -x cu
I also removed the ampersands on the function call.
Here is a simplified example based on what you have shown, primarily removing the CImg stuff and some other unnecessary items:
$ cat main.cpp
#include "convolve.h"
int main(){
int var1 = 0;
int var2 = 1;
convolve(var1, var2);
}
$ cat convolve.h
void convolve(int &, int &);
$ cat convolve.cu
#include "convolve.h"
__global__ void kernel(){};
void convolve(int & i1, int & i2){
kernel<<<1,1>>>();
}
$ cat Makefile
CC=nvcc
CX=g++
IDIR = .
special_IDIR = /usr/local/cuda-9.1/include
LDIR = /usr/local/cuda-9.1/lib64
CFLAGS=-I$(special_IDIR) -L$(LDIR)
LIBS =
ODIR = .
_DEPS = convolve.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = main.o convolve.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.cu $(DEPS)
$(CC) -c -x cu -o $# $< $(CFLAGS)
$(ODIR)/%.o: %.cpp $(DEPS)
$(CX) -c -x c++ -o $# $< $(CFLAGS) $(LIBS)
all: $(OBJ)
$(CC) -o $# $^ $(CFLAGS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
$ make clean
rm -f ./*.o *~ core /*~
$ make
g++ -c -x c++ -o main.o main.cpp -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
nvcc -c -x cu -o convolve.o convolve.cu -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
nvcc -o all main.o convolve.o -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
$
change the instances of cuda-9.1 to cuda-9.0 in the above Makefile if you have CUDA 9.0 in your setup. The linker libs (-L) are not really needed for the compile commands, however. When linking with nvcc as we are doing here, it's also unnecessary to pass the -I and -L switches that refer to the CUDA includes and CUDA libraries that are part of the toolkit. nvcc already knows how to find those.
There may be any number of additional recommendations or tweaks to the Makefile, for instance the -x cu and -x c++ switches are probably unnecessary (at least they are unnecessary for my simplified example) but my objective here is not to create the perfect Makefile, but to give you a roadmap to get past the issue you are currently witnessing.

Makefile compilation error from cuda/cpp program [duplicate]

I made a project split in three folders : src, include, obj
I am using CImg.h and cuda.h library.
I declare void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &);in convolve.h
and define it in convolve.cu
my files :
main.cpp :
#include "CImg.h"
#include "../include/convolve.h"
using namespace cimg_library;
int main(){
CImg<float> var1("/*path*/");
CImg<float> var2("/*path2*/");
convolve(var1,var2);
//some code
}
convolve.h :
1 #ifndef CONVOLVE_H
2 #define CONVOLVE_H
//some define
10 void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &);
11 #endif //CONVOLVE_H
convolve.cu :
1 void convolve(CImg<float>& img, const CImg<float>& kernel){
//some code
24 kernel<<<dimGrid,dimBlocks>>>(/*some arg*/);
}
and my new makefile :
1 CC=nvcc
2 CX=g++
3 IDIR =../include
4 special_IDIR = /usr/local/cuda-9.0/include
5 LDIR = /usr/local/cuda-9.0/lib64
6 CFLAGS=-I$(special_IDIR) -L$(LDIR)
7
8 LIBS = -lX11 -lpthread -lcudart
9 ODIR = ../obj
10
11
12 _DEPS = convolve.h kernel.cuh
13 DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
14
15 _OBJ = main.o convolve.o kernel.o
16 OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
17
18 $(ODIR)/%.o: %.cpp $(DEPS)
19 $(CX) -x c++ -o $# $< $(CFLAGS) $(LIBS)
20
21 $(ODIR)/%.o: %.cu $(DEPS)
22 $(CC) -cu -o $# $< $(CFLAGS)
23
24 all: $(OBJ)
25 $(CC) -o $# $^ $(CFLAGS)
26
27
28 .PHONY: clean
29
30 clean:
31 rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
Here is my issue : it says the reference to void convolve(cimg_library::CImg<float>&, cimg_library::CImg<float> const &) is undefined.
I think this is because I never clearly say to the compiler that the definition of convolve is in convolve.cu. But I do not find how to make this link properly.
Thanks for your help !
please don't post code (or Makefile contents) with line numbers. It just gets in the way, usually.
The compilation process here follows a compile...link process. The first stage is the compile stage, and you should be using -c for both g++ and nvcc during this stage (i.e. for both types of Makefile targets)
nvcc has no -cu option. I think maybe you meant -x cu
I also removed the ampersands on the function call.
Here is a simplified example based on what you have shown, primarily removing the CImg stuff and some other unnecessary items:
$ cat main.cpp
#include "convolve.h"
int main(){
int var1 = 0;
int var2 = 1;
convolve(var1, var2);
}
$ cat convolve.h
void convolve(int &, int &);
$ cat convolve.cu
#include "convolve.h"
__global__ void kernel(){};
void convolve(int & i1, int & i2){
kernel<<<1,1>>>();
}
$ cat Makefile
CC=nvcc
CX=g++
IDIR = .
special_IDIR = /usr/local/cuda-9.1/include
LDIR = /usr/local/cuda-9.1/lib64
CFLAGS=-I$(special_IDIR) -L$(LDIR)
LIBS =
ODIR = .
_DEPS = convolve.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = main.o convolve.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: %.cu $(DEPS)
$(CC) -c -x cu -o $# $< $(CFLAGS)
$(ODIR)/%.o: %.cpp $(DEPS)
$(CX) -c -x c++ -o $# $< $(CFLAGS) $(LIBS)
all: $(OBJ)
$(CC) -o $# $^ $(CFLAGS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
$ make clean
rm -f ./*.o *~ core /*~
$ make
g++ -c -x c++ -o main.o main.cpp -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
nvcc -c -x cu -o convolve.o convolve.cu -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
nvcc -o all main.o convolve.o -I/usr/local/cuda-9.1/include -L/usr/local/cuda-9.1/lib64
$
change the instances of cuda-9.1 to cuda-9.0 in the above Makefile if you have CUDA 9.0 in your setup. The linker libs (-L) are not really needed for the compile commands, however. When linking with nvcc as we are doing here, it's also unnecessary to pass the -I and -L switches that refer to the CUDA includes and CUDA libraries that are part of the toolkit. nvcc already knows how to find those.
There may be any number of additional recommendations or tweaks to the Makefile, for instance the -x cu and -x c++ switches are probably unnecessary (at least they are unnecessary for my simplified example) but my objective here is not to create the perfect Makefile, but to give you a roadmap to get past the issue you are currently witnessing.

Linking static library with gnu g++: No such file or directory, Makefile

I'm using makefile to compile my simple application. Here it is:
CURRDIR = `basename $(PWD)`
MAINAPP = main
SECTION = section
POINT = point
FIGURE = figure
CIRCLE = circle
TRIANGLE = triangle
RECTANGLE = rectangle
MAINSRC = $(MAINAPP).cpp
SECTIONSRC = $(SECTION).cpp
CIRCLESRC = $(CIRCLE).cpp
TRIANGLESRC = $(TRIANGLE).cpp
RECTANGLESRC = $(RECTANGLE).cpp
MAINKOM = $(MAINAPP).o
SECTIONKOM = $(SECTION).o
CIRCLEKOM = $(CIRCLE).o
TRIANGLEKOM = $(TRIANGLE).o
RECTANGLEKOM = $(RECTANGLE).o
SECTIONHEADER = $(SECTION).h
POINTHEADER = $(POINT).h
CIRCLEHEADER = $(CIRCLE).h
TRIANGLEHEADER = $(TRIANGLE).h
RECTANGLEHEADER = $(RECTANGLE).h
FIGUREHEADER = $(FIGURE).h
MAINEXE = $(MAINAPP).x
COMPILER = g++
COMPILERCOPTIONS = -Wall -c
LINKER = $(COMPILER)
LINOP = -Wall
BIBSTAT = libfigures.a
BIBKOM = section.o triangle.o rectangle.o circle.o
AR = ar
AROP = rv
$(BIBSTAT): $(BIBKOM)
$(AR) $(AROP) $# $?
all: $(MAINEXE)
$(SECTIONKOM): $(SECTIONSRC)
$(COMPILER) $(COMPILERCOPTIONS) $(SECTIONSRC)
$(CIRCLEKOM): $(CIRCLESRC)
$(COMPILER) $(COMPILERCOPTIONS) $(CIRCLESRC)
$(TRIANGLEKOM): $(TRIANGLESRC)
$(COMPILER) $(COMPILERCOPTIONS) $(TRIANGLESRC)
$(RECTANGLEKOM): $(RECTANGLESRC)
$(COMPILER) $(COMPILERCOPTIONS) $(RECTANGLESRC)
$(MAINKOM): $(MAINSRC) $(SECTIONHEADER) $(POINTHEADER) $(CIRCLEHEADER) $(TRIANGLEHEADER) $(RECTANGLEHEADER) $(FIGUREHEADER)
$(COMPILER) $(COMPILERCOPTIONS) $(MAINSRC)
$(MAINEXE): $(MAINKOM) $(SECTIONKOM) $(CIRCLEKOM) $(TRIANGLEKOM) $(RECTANGLEKOM) $(BIBSTAT)
$(LINKER) -o $# $(LINOP) $^ $(MAINEXE) $(MAINKOM) $(SECTIONKOM) $(CIRCLEKOM) $(TRIANGLEKOM) $(RECTANGLEKOM)
run: $(MAINEXE)
./$(MAINEXE)
clean:
rm -f a.out *~ *.o *.x
tar: clean
(cd ..; tar cvzf $(CURRDIR).tar.gz $(CURRDIR); ls -altr)
However, it seems that I have a problem with linking static library. This is my output after executing make all:
$ make all
g++ -Wall -c main.cpp
g++ -Wall -c section.cpp
g++ -Wall -c circle.cpp
g++ -Wall -c triangle.cpp
g++ -Wall -c rectangle.cpp
ar rv libfigures.a section.o triangle.o rectangle.o circle.o
ar: creating libfigures.a
a - section.o
a - triangle.o
a - rectangle.o
a - circle.o
g++ -o main.x -Wall main.o section.o circle.o triangle.o rectangle.o libfigures.a main.x main.o section.o circle.o triangle.o rectangle.o
g++: error: main.x: No such file or directory 1
make: *** [main.x] Error 1
Any ideas what am I doing wrong with this makefile?
Your final command is
g++ -o main.x -Wall main.o section.o circle.o triangle.o rectangle.o \
libfigures.a main.x main.o section.o circle.o triangle.o \
rectangle.o
There's too much going on here: you (1) repeat each object twice (2) use both objects and a library built from them (3) use the output file in the list of input files.
It should be
g++ -o main.x main.o libfigures.a
You probably need to modify the makefile rule like this:
$(MAINEXE): $(MAINKOM) $(BIBSTAT)
$(LINKER) -o $# $^

How to add directive in make file in c++

Is this the correct way of defining GLES_VERSION ?? I m getting #error in my program
c++ code
#if GLES_VERSION == 2
#include <GLES2/gl2.h>
#elif GLES_VERSION == 3
#include <GLES3/gl3.h>
#else
#error "GLES_VERSION must be defined as either 2 or 3"
#endif
i m ending up here in #error
make file code
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
OBJS = hello.o
LIBS = -lX11 -lXau -lEGL -lGLESv2 -lm
GLES_VERSION = -D2 #is this correct ?
TARGET = hello \
$(TARGET): $(OBJS)
$(CXX) -o $(TARGET) $(GLES_VERSION) $(OBJS) $(LIBS)
all: $(TARGET)
clean:
rm -f $(OBJS) $(TARGET)
It should be
GLES_VERSION = -DGLES_VERSION=2
it must be,
GLES_VERSION = -DGLES_VERSION=2

C++ Ruby Extension with External Libraries

I started a little experiment today: I wrote a C++ class which depends on some other libraries (ALGLIB, Eigen, internal tools) and I wanted to create a Ruby wrapper for that class. I'm currently using Rice to do that. First I wrote a very simple C++ wrapper for my class:
// #file MLPWrapper.h
#pragma once
#include "mlp/MLP.h"
#include <ruby.h>
class MLPWrapper
{
MLP mlp; // <- my C++ class
public:
...
void fit()
{
...
mlp.fit(stop);
}
};
The library's cpp-file is this:
// #file cmlp.cpp
#include "rice/Data_Type.hpp"
#include "rice/Constructor.hpp"
#include "MLPWrapper.h"
using namespace Rice;
extern "C"
void Init_cmlp()
{
Data_Type<MLPWrapper> rb_cMLPWrapper = define_class<MLPWrapper>("MLP")
.define_constructor(Constructor<MLPWrapper>())
...
.define_method("fit", &MLPWrapper::fit);
}
And this is the extconf.rb:
require "mkmf-rice"
$CFLAGS << "-O3"
HEADER_DIRS = [
"..",
"../../external/libraries/eigen-eigen-3.0.1",
"../../external/libraries/alglib/cpp/src",
"../../external/libraries/CMA-ESpp"
]
LIB_DIRS = [
"../../build/external/libraries/alglib/cpp/src",
"../../build/external/libraries/CMA-ESpp/cma-es",
"../../build/src/tools"
]
dir_config("libs", HEADER_DIRS, LIB_DIRS)
have_library("libtools")
have_library("libalglib")
create_makefile("cmlp")
Everything works fine except linking. Obviously the header files of the libraries are included, otherwise it would not compile. But when I run a little test program ("require "cmlp"; mlp = MLP.new") in Ruby it does not find the symbol _ZN6LoggerC1ENS_6TargetESs, which is part of libtools (an enum). This is what happens when I build the C++ extension and execute the test program:
$ ruby extconf.rb
checking for main() in -lrice... yes
checking for main() in -llibtools... no
checking for main() in -llibalglib... no
checking for main() in -llibcmaes... no
creating Makefile
$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I.. -I../../external/libraries/eigen-eigen-3.0.1 -I../../external/libraries/alglib/cpp/src -I../../external/libraries/CMA-ESpp -I/var/lib/gems/1.8/gems/rice-1.4.3/ruby/lib/include -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -O3 -Wall -g -c cmlp.cpp
g++ -shared -o cmlp.so cmlp.o -L. -L/usr/lib -L../../build/external/libraries/alglib/cpp/src -L../../build/external/libraries/CMA-ESpp/cma-es -L../../build/src/tools -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -L/var/lib/gems/1.8/gems/rice-1.4.3/ruby/lib/lib -lrice -lruby1.8 -lpthread -lrt -ldl -lcrypt -lm -lc
$ ruby test.rb
ruby: symbol lookup error: ./cmlp.so: undefined symbol: _ZN6LoggerC1ENS_6TargetESs
The libraries are all compiled with CMake (add_library(...)) and are located at
../../build/src/tools/libtools.so
../../build/external/libraries/alglib/cpp/src/libalglib.so
../../build/external/libraries/CMA-ESpp/cma-es/libcmaes.so
I don't know how to solve this problem on my own and I could not find any helpful documentation for my problem. How do i fix this extconf.rb? I appreciate every hint.
edit: OK, I changed the extconf.rb:
require "rubygems"
require "mkmf-rice"
BASE_DIR = "/bla/"
$CFLAGS << " -O3"
dir_config("tools", [BASE_DIR + "src", BASE_DIR + "external/libraries/eigen-eigen-3.0.1"], BASE_DIR + "build/src/tools")
unless have_library("tools")
abort "tools are missing. please compile tools"
end
dir_config("alglib", BASE_DIR + "external/libraries/alglib/cpp/src", BASE_DIR + "build/external/libraries/alglib/cpp/src")
unless have_library("alglib")
abort "alglib is missing. please compile alglib"
end
dir_config("cmaes", BASE_DIR + "external/libraries/CMA-ESpp", BASE_DIR + "build/external/libraries/CMA-ESpp/cma-es")
unless have_library("cmaes")
abort "cmaes is missing. please compile cmaes"
end
create_makefile("cmlp")
The generated Makefile is:
SHELL = /bin/sh
#### Start of system configuration section. ####
srcdir = .
topdir = /usr/lib/ruby/1.8/x86_64-linux
hdrdir = $(topdir)
VPATH = $(srcdir):$(topdir):$(hdrdir)
exec_prefix = $(prefix)
prefix = $(DESTDIR)/usr
sharedstatedir = $(prefix)/com
mandir = $(prefix)/share/man
psdir = $(docdir)
oldincludedir = $(DESTDIR)/usr/include
localedir = $(datarootdir)/locale
bindir = $(exec_prefix)/bin
libexecdir = $(prefix)/lib/ruby1.8
sitedir = $(DESTDIR)/usr/local/lib/site_ruby
htmldir = $(docdir)
vendorarchdir = $(vendorlibdir)/$(sitearch)
includedir = $(prefix)/include
infodir = $(prefix)/share/info
vendorlibdir = $(vendordir)/$(ruby_version)
sysconfdir = $(DESTDIR)/etc
libdir = $(exec_prefix)/lib
sbindir = $(exec_prefix)/sbin
rubylibdir = $(libdir)/ruby/$(ruby_version)
docdir = $(datarootdir)/doc/$(PACKAGE)
dvidir = $(docdir)
vendordir = $(libdir)/ruby/vendor_ruby
datarootdir = $(prefix)/share
pdfdir = $(docdir)
archdir = $(rubylibdir)/$(arch)
sitearchdir = $(sitelibdir)/$(sitearch)
datadir = $(datarootdir)
localstatedir = $(DESTDIR)/var
sitelibdir = $(sitedir)/$(ruby_version)
CC = gcc
LIBRUBY = $(LIBRUBY_SO)
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
LIBRUBYARG_STATIC = -lruby1.8-static
RUBY_EXTCONF_H =
CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags) -O3
INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.
DEFS =
CPPFLAGS = -I/bla/external/libraries/CMA-ESpp -I/bla//external/libraries/alglib/cpp/src -I//bla/src -I/bla/external/libraries/eigen-eigen-3.0.1 -I/var/lib/gems/1.8/gems/rice-1.4.3/ruby/lib/include
CXXFLAGS = $(CFLAGS) -Wall -g
ldflags = -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -L/var/lib/gems/1.8/gems/rice-1.4.3/ruby/lib/lib
dldflags =
archflag =
DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
LDSHARED = g++ -shared
AR = ar
EXEEXT =
RUBY_INSTALL_NAME = ruby1.8
RUBY_SO_NAME = ruby1.8
arch = x86_64-linux
sitearch = x86_64-linux
ruby_version = 1.8
ruby = /usr/bin/ruby1.8
RUBY = $(ruby)
RM = rm -f
MAKEDIRS = mkdir -p
INSTALL = /usr/bin/install -c
INSTALL_PROG = $(INSTALL) -m 0755
INSTALL_DATA = $(INSTALL) -m 644
COPY = cp
#### End of system configuration section. ####
preload =
CXX = g++
libpath = . $(libdir) /bla/external/libraries/CMA-ESpp/cma-es /bla/build/external/libraries/alglib/cpp/src /bla/build/src/tools
LIBPATH = -L. -L$(libdir) -L/bla/build/external/libraries/CMA-ESpp/cma-es -L/bla/build/external/libraries/alglib/cpp/src -L/bla/build/src/tools
DEFFILE =
CLEANFILES = mkmf.log
DISTCLEANFILES =
extout =
extout_prefix =
target_prefix =
LOCAL_LIBS =
LIBS = -lcmaes -lalglib -ltools -lrice -lruby1.8 -lpthread -lrt -ldl -lcrypt -lm -lc
SRCS = cmlp.cpp
OBJS = cmlp.o
TARGET = cmlp
DLLIB = $(TARGET).so
EXTSTATIC =
STATIC_LIB =
BINDIR = $(bindir)
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
TARGET_SO = $(DLLIB)
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
all: $(DLLIB)
static: $(STATIC_LIB)
clean:
#-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
distclean: clean
#-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
#-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
realclean: distclean
install: install-so install-rb
install-so: $(RUBYARCHDIR)
install-so: $(RUBYARCHDIR)/$(DLLIB)
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
install-rb: pre-install-rb install-rb-default
install-rb-default: pre-install-rb-default
pre-install-rb: Makefile
pre-install-rb-default: Makefile
$(RUBYARCHDIR):
$(MAKEDIRS) $#
site-install: site-install-so site-install-rb
site-install-so: install-so
site-install-rb: install-rb
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
.cc.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cxx.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.cpp.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.C.o:
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
.c.o:
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
$(DLLIB): $(OBJS) Makefile
#-$(RM) $#
$(LDSHARED) -o $# $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
$(OBJS): ruby.h defines.h
../../build/src/tools/libtools.so
../../build/external/libraries/alglib/cpp/src/libalglib.so
../../build/external/libraries/CMA-ESpp/cma-es/libcmaes.so
could be the problem. I would try absolute paths here, I could imagine that the pwd is a different one than you expected while running ruby extconf.rb.
Also, I assume you need a dir_config entry for each library you'd like to link in. So
dir_config('libs', HEADER_DIRS, LIB_DIRS)
should be replaced by
dir_config('tools', '<Path to include dir>', '<Path to lib dir>')
dir_config('alglib', '<Path to include dir>', '<Path to lib dir>')
Note that the leading 'lib' should be omitted, just like you would in the -l linker option.
Next, if you want to be absolutely sure that a library is found, replace
have_library('libtools')
by
have_library('tools') or raise
Again, 'lib' is omitted.
If you still can't solve the problem, please post the Makefile generated by `ruby extconf.rb'.