Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7782 Discussions

Question concerning behavior of Intel-linker on Linux

alexvi
Beginner
148 Views

Hi,

We came across different behavior of HP-linker on HP-UX and Intel-linker

on Linux.

We have two libraries:

*) libaaa.so and libbbb.so,

*) libbbb.so depends on libaaa.so.

HP-UX linker allows to build exe-file as follows:

aCC main.o libbbb.so

GNU linker on Linux requires the following build of exe-file

icpc main.o libaaa.so libbbb.so

Note.

Command line

> icpc main.o libbbb.so

produces error-message.

What is a reason for such behavior og Intel-linker?

Thanks.

Details below.

>>>>>> 1. SOURCE FILES <<<<<<

------ File aaa.h ------

#ifndef AAA_HH

#define AAA_HH

struct AAA

{

AAA();

virtual ~AAA();

};

#endif

------------------------

----- File aaa.cpp -----

#include "./aaa.h"

AAA::AAA()

{

}

AAA::~AAA()

{

}

------------------------

------ File bbb.h ------

#ifndef BBB_HH

#define BBB_HH

#include "./aaa.h"

struct BBB : public AAA

{

BBB();

~BBB();

};

#endif

------------------------

----- File bbb.cpp -----

#include "./bbb.h"

BBB::BBB()

:

AAA()

{

}

BBB::~BBB()

{

}

------------------------

----- File main.cpp ----

#include "./bbb.h"

int main()

{

BBB b;

return 0;

}

------------------------

>>>>>> 2. MAKEFILES <<<<<<

====== Makefile.hp (HP-UX) ======

CC = aCC +DD64 -AA -mt -c -g -I`pwd`

LDLIB = aCC +DD64 -AA -mt -b -g

LDEXE = aCC +DD64 -AA -mt -g

RM = rm -rf

ECHO = echo

all: info clean objs libs exe

info:

@$(ECHO) ====== INFO ======

@$(ECHO) $(CC)

@$(ECHO) $(LDLIB)

@$(ECHO) $(LDLIB)

clean:

@$(ECHO) ====== CLEAN ======

$(RM) ./*.o ./*.so ./*.out

objs:

@$(ECHO) ====== OBJS ======

$(CC) aaa.cpp

$(CC) bbb.cpp

$(CC) main.cpp

libs:

@$(ECHO) ====== LIBS ======

$(LDLIB) -o ./libaaa.so ./aaa.o

$(LDLIB) -o ./libbbb.so ./bbb.o ./libaaa.so

exe:

@$(ECHO) ====== EXE ======

$(LDEXE) -o ./hp1.out ./main.o ./libaaa.so ./libbbb.so

$(LDEXE) -o ./hp2.out ./main.o ./libbbb.so

==================================

------ Makefile.lin (Linux) ------

CC = icpc -c -m64 -fPIC -g

LDLIB = icpc -shared -g

LDEXE = icpc -g

RM = rm -rf

ECHO = echo

all: info clean objs libs exe

info:

@$(ECHO) ====== INFO ======

@$(ECHO) $(CC)

@$(ECHO) $(LDLIB)

@$(ECHO) $(LDLIB)

clean:

@$(ECHO) ====== CLEAN ======

$(RM) ./*.o ./*.so ./*.out

objs:

@$(ECHO) ====== OBJS ======

$(CC) aaa.cpp

$(CC) bbb.cpp

$(CC) main.cpp

libs:

@$(ECHO) ====== LIBS ======

$(LDLIB) -o ./libaaa.so ./aaa.o

$(LDLIB) -o ./libbbb.so ./bbb.o ./libaaa.so

exe:

@$(ECHO) ====== EXE ======

$(LDEXE) -o ./lin1.out ./main.o ./libaaa.so ./libbbb.so

$(LDEXE) -o ./lin2.out ./main.o ./libbbb.so

==================================

>>>>>> 3. COMPILATION <<<<<<

------ Compilation on HP-UX ------

HP-UX B.11.23 U ia64 1139467043 unlimited-user license

aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]

92453-07 linker ld HP Itanium B.12.54 IPF/IPF

REL Tue, Dec 8, 2009 01:08:02 PM PST

> make -f Makefile.hp

====== INFO ======

aCC +DD64 -AA -mt -c -g -I/devjuser/jp/ccjp/avinokur/investigation/

002_hp

aCC +DD64 -AA -mt -b -g

aCC +DD64 -AA -mt -b -g

====== CLEAN ======

rm -rf ./*.o ./*.so ./*.out

====== OBJS ======

aCC +DD64 -AA -mt -c -g -I`pwd` aaa.cpp

aCC +DD64 -AA -mt -c -g -I`pwd` bbb.cpp

aCC +DD64 -AA -mt -c -g -I`pwd` main.cpp

====== LIBS ======

aCC +DD64 -AA -mt -b -g -o ./libaaa.so ./aaa.o

aCC +DD64 -AA -mt -b -g -o ./libbbb.so ./bbb.o ./libaaa.so

====== EXE ======

aCC +DD64 -AA -mt -g -o ./hp1.out ./main.o ./libaaa.so ./libbbb.so

aCC +DD64 -AA -mt -g -o ./hp2.out ./main.o ./libbbb.so

----------------------------------

------ Compilation on Linux ------

Linux 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64

x86_64 x86_64 GNU/Linux

Intel C++ Intel 64 Compiler XE for applications running on

Intel 64, Version 12.0.0.084 Build 20101006

Copyright (C) 1985-2010 Intel Corporation. All rights reserved.

GNU ld version 2.17.50.0.6-14.el5 20061020

> make -f Makefile.lin

====== INFO ======

icpc -c -m64 -fPIC -g

icpc -shared -g

icpc -shared -g

====== CLEAN ======

rm -rf ./*.o ./*.so ./*.out

====== OBJS ======

icpc -c -m64 -fPIC -g aaa.cpp

icpc -c -m64 -fPIC -g bbb.cpp

icpc -c -m64 -fPIC -g main.cpp

====== LIBS ======

icpc -shared -g -o ./libaaa.so ./aaa.o

icpc -shared -g -o ./libbbb.so ./bbb.o ./libaaa.so

====== EXE ======

icpc -g -o ./lin1.out ./main.o ./libaaa.so ./libbbb.so

/opt/intel/compiler/lib/intel64/libimf.so: warning: warning:

feupdateenv is not implemented and will always fail

icpc -g -o ./lin2.out ./main.o ./libbbb.so

ld: warning: ./libaaa.so, needed by ./libbbb.so, not found (try using -

rpath or -rpath-link)

/opt/intel/compiler/lib/intel64/libimf.so: warning: warning:

feupdateenv is not implemented and will always fail

./libbbb.so: undefined reference to `typeinfo for AAA'

./libbbb.so: undefined reference to `AAA::~AAA()'

./libbbb.so: undefined reference to `AAA::AAA()'

make: *** [exe] Error 1

----------------------------------

0 Kudos
3 Replies
mecej4
Black Belt
148 Views
Just a couple of questions: 1) did you try linking with -rpath <path> ? 2) are both shared libraries located where they are accessible through $LD_LIBRARY_PATH ? On both systems?
alexvi
Beginner
148 Views

aCC +DD64 -AA -mt -g -o ./hp1.out ./main.o ./libaaa.so ./libbbb.so

aCC +DD64 -AA -mt -g -o ./hp2.out ./main.o ./libbbb.so

I didn't try linking with -rpath.
Both libraries are in current directory

setenv LD_LIBRARY_PATH .:$LD_LIBRARY_PATH

Now it works fine.

Thanks


P.S. LD_LIBRARY_PATH on HP doesn't contain current directory, however linkage worked fine on HP.

Alex
mecej4
Black Belt
148 Views
Many GNU versions of binutils (such as ld) have more options and slightly different behavior than corresponding SysV or BSD versions of a different vintage. There is a Posix standard that covers these utilities, but I do not know if it is worthwhile to keep track of standards-compliance.

By the way, the Intel compilers on Linux use the system binutils. As far as I know, there has never been an Intel-supplied set containing ld, ar, as, etc.
Reply