View Full Version : Please help change from Linux to Mac OS (makefile)

Apr 19, 2011, 09:08 AM
Hi, I'm a newbie in Mac programming, used to work on ubuntu. Below is a makefile which works in Ubuntu, but when i run it in Mac via terminal it gives error. Can anyone tell me where to change so that i can run it without problems?

Error code is: "ar : creating archive libbg.a
ranlib: warning for library: libbg.a the table of contents is empty (no object file members in the library define global symbols)"

Thanks in advance for any help! :)

Original Code for Ubuntu is here:
# Makefile for the bgcpp-Library
# +------------------------------------------------------------------+
# | Modify also the file sysdef.h depending on the target machine ! |
# +------------------------------------------------------------------+

# Uncomment the following definitions for OS/2 (see also below) :

# CC = gcc
# CLIBFLAGS = -O -c -Wall -frepo -fhandle-exceptions -s
# CFLAGS = -Wall -fhandle-exceptions -lbgcpp -lm -lstdcpp -s
# H_PATH = \home\bg\lib\

# Uncomment the following definitions for Linux (see also below):

CC = gcc
CLIBFLAGS = -I../../lib -O -c -Wall -s
CFLAGS = -I../../lib -L../../lib -Wall -lbg -lm -lstdc++ -s
PLOTFLAGS = -L/usr/X11/lib -lplotter -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11
H_PATH = ../../lib/

BG_OBJ = bgcolor.o \
bgdata.o \
bgliberr.o \
bgstring.o \
centsums.o \
difutil.o \
fallible.o \
fft.o \
files.o \
fresnel.o \
geometry.o \
getkey.o \
histogr.o \
ifparser.o \
inputbuf.o \
mathutil.o \
nmrutil.o \
outbuf.o \
physutil.o \
randgaus.o \
randgen.o \
solve.o \
strfunc.o \
tgapict.o \
unitcell.o \

%.o: %.cc
$(CC) $(CLIBFLAGS) -o $@ $<

bgaxis.o: bgaxis.cc $(H_PATH)bggraphics.h
bgcolor.o: bgcolor.cc $(H_PATH)bggraphics.h
bgdata.o: bgdata.cc $(H_PATH)bgdata.h
bgliberr.o: bgliberr.cc $(H_PATH)bgliberr.h
bgplotter.o: bgplotter.cc $(H_PATH)bggraphics.h
bgstring.o: bgstring.cc $(H_PATH)bgstring.h
centmoments.o: centmoments.cc $(H_PATH)stochast.h
centsums.o: centsums.cc $(H_PATH)stochast.h
deuteronnmr.o: deuteronnmr.cc $(H_PATH)nmrutil.h
difutil.o: difutil.cc $(H_PATH)difutil.h
fallible.o: fallible.cc $(H_PATH)fallible.h
files.o: files.cc $(H_PATH)bglib.h
fft.o: fft.cc $(H_PATH)fft.h
fresnel.o: fresnel.cc $(H_PATH)mathutil.h
geometry.o: geometry.cc $(H_PATH)geometry.h
getkey.o: getkey.cc $(H_PATH)bglib.h
histogr.o: histogr.cc $(H_PATH)stochast.h
ifparser.o: ifparser.cc $(H_PATH)iobuffer.h
inputbuf.o: inputbuf.cc $(H_PATH)iobuffer.h
mathutil.o: mathutil.cc $(H_PATH)mathutil.h
nmrutil.o: nmrutil.cc $(H_PATH)nmrutil.h
outbuf.o: outbuf.cc $(H_PATH)iobuffer.h
physutil.o: physutil.cc $(H_PATH)physutil.h
randgaus.o: randgaus.cc $(H_PATH)stochast.h
randgen.o: randgen.cc $(H_PATH)stochast.h
solve.o: solve.cc $(H_PATH)mathutil.h
strfunc.o: strfunc.cc $(H_PATH)bglib.h
tgapict.o: tgapict.cc $(H_PATH)tgapict.h
unitcell.o: unitcell.cc $(H_PATH)simulation.h

# Uncomment the following for OS/2
# bgcpp: $(BGCPP_OBJ)
# @ar r bgcpp.a $(BGCPP_OBJ)
# @ar s bgcpp.a
# @copy bgcpp.a \home\bg\lib > NUL
# @del *.o > NUL

# Uncomment the following for Linux

libbg: $(BG_OBJ)
@rm -f libbg.a
@ar qv libbg.a $(BG_OBJ) > /dev/null
@ranlib libbg.a
@cp libbg.a $(H_PATH)libbg.a

bglib: libbg

@rm -f *~
@rm -f *.o
@rm -f libbg.a
@rm -f a.out

testlib: $(BG_OBJ) testlib.cc
$(CC) testlib.cc -o testlib $(PLOTFLAGS) $(CFLAGS)

all: libbg testlib

Apr 19, 2011, 10:11 AM
Not sure what the problem is, but here are some suggestions for troubleshooting.

First remove the redirection to /dev/null for the ar command, and look at the output that the -v option is giving you.

You might also consider using libtool instead of ar + ranlib.

Apr 20, 2011, 09:18 AM
Wenn remove the /dev/null, output is:

ar: creating archive libbg.a
q - bgcolor.o
q - bgdata.o
q - bgliberr.o
q - bgstring.o
q - centmoments.o
q - centsums.o
q - deuteronnmr.o
q - difutil.o
q - fallible.o
q - fft.o
q - files.o
q - fresnel.o
q - geometry.o
q - getkey.o
q - histogr.o
q - ifparser.o
q - inputbuf.o
q - mathutil.o
q - nmrutil.o
q - outbuf.o
q - physutil.o
q - randgaus.o
q - randgen.o
q - solve.o
q - strfunc.o
q - tgapict.o
q - unitcell.o
ranlib: warning for library: libbg.a the table of contents is empty (no object file members in the library define global symbols)

And i'm not sure what the -v Option is

GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A

This program built for i386-apple-darwin10.0

Apr 20, 2011, 09:46 AM
> no object file members in the library define global symbols

Are your .o files empty?
Can you post one of your .cc files and one of your .h files?

May 19, 2011, 02:29 AM
Problem solved, i forgot that all the .o files are created in ubuntu. I recreate them again in OS and now the compile is done without errors. :D
Thanks for all the help and hints. :)

Mar 4, 2012, 11:17 PM
hi friend
I met the same problem as you , but I tried to remove all the .o files , and rebuilt again , but still has the same problem , I put my question here
, if you know the answer , could you please kindly answer it there , thanks so much .