Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

newbie question

ascotilla
Beginner
633 Views
Hi all,

I might be asking something stupid, but I have a problem with running a model which I finally manage to compile in a mac. I already worked with the model in a PC, and I'm using the same makefile for the compilation (adapted, as far as I'm able to, to the Mac paths). However, I can't run it because it's still looking for the libraries in the /home/myuser folder instead of the Mac's equivalent /Users/myuser, where the library is actually placed.

This is the error I get when trying to run it:

dyn1003-29:archivos_para_correr_programa_vs6 mmartinc$ ./motif_lpj-step1a
dyld: Library not loaded: /home/mmartinc/local/lib/libnetcdf_c++.4.dylib
Referenced from: /Users/mmartinc/Desktop/archivos_para_correr_programa_vs6/./motif_lpj-step1a
Reason: image not found
Trace/BPT trap
dyn1003-29:archivos_para_correr_programa_vs6 mmartinc$


This is the part of the makefile where the paths are set up:

NETCDF =/Users/mmartinc/local

FC = ifort
FCOPTIONS = -fpp -O3

CPPOPTIONS = -I$(NETCDF)/include
CXX = icpc
CXXOPTIONS = -O3


CXXOPTIONS = -std=c++0x -O3
LD = $(FC)
LDLIBS1 = -I$(NETCDF)/lib/lnetcdf_c++
LDLIBS2 = -I$(NETCDF)/lib/-lnetcdf -lstdc++ -L$(NETCDF)/lib -lnetcdf -lnetcdf_c++
LDLIBS = -L$(NETCDF)/lib -lnetcdf_c++ -lnetcdf -L/Developer/opt/intel -lstdc++


Do you have any idea of where is it getting the /home/myuser path from??

Thanks in advance!!

0 Kudos
12 Replies
TimP
Honored Contributor III
633 Views
Starting with basics, you must have the environment variable NETCDF set so that it agrees with the way your file system is set up. Typically, you must first install netcdf there (possibly building it from source).
0 Kudos
ascotilla
Beginner
633 Views
Thanks for the answer, TimP

I'm not sure if I'm following you. I already installed the NetCDF from source, and /Users/mmartinc/local is where it's placed, so I don't see how can it be related to the error...:-S
0 Kudos
mecej4
Honored Contributor III
633 Views
The answer is there for the asking:

Library not loaded: /home/mmartinc/local/lib/libnetcdf_c++.4.dylib
Referenced from: /Users/mmartinc/Desktop/archivos_para_correr_programa_vs6/./motif_lpj-step1a

It is likely that the library motif_lpj-step1a... was built with a reference to /home/mmartinc/local/lib/libnetcdf_c++.4.dylib. When the former is read by the linker it looks for the reference, and does not find it.

Did you build these libraries or do they come from elsewhere with precribed locations?

0 Kudos
ascotilla
Beginner
633 Views
Hi mecej4,

That's what I thought at the beginning, but motif_lpj-step1a is created during the compilation (is one of the executables I get). I've searched for any path pointing to the /home directory amongst the files involved in the compilation, but I found nothing.

The makefile compiles together two sections of the model, one in fortran (the main part) and the other one in c++ (for input-outputs). The run is controled by a configuration file, on which the paths have also been changed.

I tried to change dyld path but still doesn't work, and with my knowledge I'm running out of ideas..:-S

Thanks in advance!!


0 Kudos
mecej4
Honored Contributor III
633 Views
I am not familiar with OSX; is there a utility similar to "ldd" in Linux, which when run on an executable or shared library lists the library dependencies? If so, you could run it on your motif_lpj-step1a object.
0 Kudos
ascotilla
Beginner
633 Views
Thanks, I'll look out for it and tell you if I make any advances.
0 Kudos
ascotilla
Beginner
633 Views
Ok,

I found the command for Mac, which is otool (otool -l filename for the loading information). The info about where does it look for the libraries is at the end of the file, and I copy it here:

Load command 10
cmd LC_LOAD_DYLIB
cmdsize 72
name /home/mmartinc/local/lib/libnetcdf_c++.4.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 6.0.0
compatibility version 6.0.0
Load command 11
cmd LC_LOAD_DYLIB
cmdsize 72
name /home/mmartinc/local/lib/libnetcdf.7.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 9.1.0
compatibility version 9.0.0
Load command 12
cmd LC_LOAD_DYLIB
cmdsize 56
name /usr/lib/libstdc++.6.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 7.9.0
compatibility version 7.0.0
Load command 13
cmd LC_LOAD_DYLIB
cmdsize 56
name /usr/lib/libgcc_s.1.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 830.0.0
compatibility version 1.0.0
Load command 14
cmd LC_LOAD_DYLIB
cmdsize 48
name /usr/lib/libmx.A.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 315.0.0
compatibility version 1.0.0
Load command 15
cmd LC_LOAD_DYLIB
cmdsize 56
name /usr/lib/libSystem.B.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 125.2.11
compatibility version 1.0.0



But I still don't know how can I change those paths..:-S

0 Kudos
ascotilla
Beginner
633 Views
I tried to open the executable motif_lpj-step1a and change the paths directly from the file (which is not the best, for sure, as I still don't know where those paths are created), and it didn't work either:

dyn1003-29:archivos_para_correr_programa_vs6 mmartinc$ ./motif_lpj-step1a
-bash: ./motif_lpj-step1a: Malformed Mach-o file
dyn1003-29:archivos_para_correr_programa_vs6 mmartinc$

What am I missing?

Thanks!
0 Kudos
ascotilla
Beginner
633 Views
I finally could run it!!

I had already tried: DYLD_LIBRARY_PATH=/Users/mmartinc/local/lib:$DYLD_LIBRARY_PATH, but it did't work. Now I tried: export DYLD_LIBRARY_PATH=/Users/mmartinc/local/lib and worked perfectly.

I don't really understand what's the difference between both, but my model is finally running!

Cheers
0 Kudos
Ron_Green
Moderator
633 Views
the 'export' controls whether child processes inherit the env variable. In most cases, you DO want new child processes launched/spawned from the current process to inherit your environment. Without the export, when you start the program using this lib, that process would not inherit the DYLD_LIBRARY_PATH.

I just about always use 'export' when setting env vars - can't remember last time I didn't.

As for setting the path to your /Users/mmartinc/local/lib - the configure --prefix option sets this.

You might consider putting the libs in /usr/local (configure --prefix=/usr/local ). However, home is kind of convenient on a Mac since when you migrate your data to a new Mac it will surely copy over the libs from your home dir. Downside is that it's an unusual place to store general purpose libraries.

ron
0 Kudos
ascotilla
Beginner
633 Views
Thanks a lot, Ron
0 Kudos
steve_j_1
Beginner
633 Views

I am implementing a stack in c++ using classes it works if i write whole code in 1 cpp file but  when i made a seprate header file  i got errors of type :

error LNK2019: unresolved external symbol "public: void __thiscall Stack<int>::Push(int)" (?Push@?$Stack@H@@QAEXH@Z) referenced in function _main

tell me how can i resolve this

0 Kudos
Reply