GNS3/dynamips

OSX compilation issue with macport

Closed this issue · 10 comments

When I compile with libelf from macport:

Started by user Julien Duponchelle
Building remotely on OSX Mavericks QT5 (qt5 mavericks macos unix) in workspace /Users/gns3/Jenkins/workspace/Nightly Build dynamips Mac OSX
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@github.com:GNS3/dynamips.git # timeout=10
Fetching upstream changes from git@github.com:GNS3/dynamips.git
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git -c core.askpass=true fetch --tags --progress git@github.com:GNS3/dynamips.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision d07032444a13190c56a0c583ac2bb301d40257ef (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d07032444a13190c56a0c583ac2bb301d40257ef
 > git rev-list d07032444a13190c56a0c583ac2bb301d40257ef # timeout=10
[Nightly Build dynamips Mac OSX] $ /bin/sh -xe /var/folders/91/q11hwpl50pv94z5m1nzlhgcr0000gn/T/hudson2662798564193564165.sh
+ mkdir -p build
+ cd build
+ cmake ..
-- CMAKE_MODULE_PATH=/Users/gns3/Jenkins/workspace/Nightly Build dynamips Mac OSX/cmake
-- dependencies - BEGIN
-- ARCH_AMD64=1
-- ARCH_X86=1
-- DYNAMIPS_ARCH=amd64
-- LIBELF_FOUND=TRUE
-- LIBELF_INCLUDE_DIRS=/opt/local/include/libelf
-- LIBELF_LIBRARIES=/opt/local/lib/libelf.a
-- LIBELF_DEFINITIONS=
-- LIBELF_LARGEFILE=
-- UUID_FOUND=TRUE
-- UUID_INCLUDE_DIR=/System/Library/Frameworks/Kernel.framework/Headers/uuid
-- UUID_LIBRARY=
-- CMAKE_THREAD_LIBS_INIT=
-- CMAKE_USE_PTHREADS_INIT=1
-- Pcap include dirs set to /usr/include
-- Pcap library set to /usr/lib/libpcap.dylib
-- PCAP_FOUND=YES
-- PCAP_INCLUDE_DIRS=/usr/include
-- PCAP_LIBRARIES=/usr/lib/libpcap.dylib
-- HAVE_PCAP=1
-- HAVE_POSIX_MEMALIGN=1
-- HAVE_IPV6=1
-- dependencies - END
-- configure - BEGIN
-- DYNAMIPS_VERSION="0.2.15-dev"
-- DYNAMIPS_ARCH=amd64
-- DYNAMIPS_CODE=unstable
-- BUILD_DYNAMIPS_STABLE=OFF
-- BUILD_DYNAMIPS_UNSTABLE=ON
-- DYNAMIPS_RENAME=auto
-- DYNAMIPS_RENAME_TARGET=dynamips_amd64_unstable
-- BUILD_NVRAM_EXPORT=ON
-- BUILD_UDP_SEND=OFF
-- BUILD_UDP_RECV=OFF
-- ENABLE_GEN_ETH=ON
-- ENABLE_IPV6=ON
-- DYNAMIPS_FLAGS=-m64;-Wall;-O2;-fomit-frame-pointer;-mdynamic-no-pic
-- DYNAMIPS_DEFINITIONS=-DHAS_POSIX_MEMALIGN=1;-DDYNAMIPS_VERSION="0.2.15-dev";-DJIT_ARCH="amd64";-DJIT_CPU=CPU_amd64;-DMIPS64_ARCH_INC_FILE="mips64_amd64_trans.h";-DPPC32_ARCH_INC_FILE="ppc32_amd64_trans.h";-DMAC64HACK;-DGEN_ETH;-DHAS_RFC2553=1;-DOSNAME=Darwin
-- DYNAMIPS_INCLUDES=/opt/local/include/libelf;/System/Library/Frameworks/Kernel.framework/Headers/uuid
-- DYNAMIPS_LIBRARIES=/opt/local/lib/libelf.a;/usr/lib/libpcap.dylib
-- configure - END
Summary:
  CMAKE_INSTALL_PREFIX               : /usr/local
  DYNAMIPS_ARCH                      : amd64
  DYNAMIPS_CODE                      : unstable
  DYNAMIPS_RENAME                    : dynamips_amd64_unstable -> dynamips  (auto)
  BUILD_NVRAM_EXPORT                 : ON
  BUILD_UDP_SEND                     : OFF
  BUILD_UDP_RECV                     : OFF
  Large File support                 : libelf is incompatible
  Linux Ethernet (RAW sockets)       : no, not Linux  (linux_eth)
  Generic Ethernet (libpcap/WinPcap) : ENABLE_GEN_ETH=ON  (gen_eth)
  IPv6 support (RFC 2553)            : ENABLE_IPV6=ON
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/gns3/Jenkins/workspace/Nightly Build dynamips Mac OSX/build
+ make
[  1%] Building C object stable/CMakeFiles/nvram_export.dir/__/common/nvram_export.c.o
In file included from /Users/gns3/Jenkins/workspace/Nightly Build dynamips Mac OSX/common/nvram_export.c:14:
In file included from /Users/gns3/Jenkins/workspace/Nightly Build dynamips Mac OSX/common/dynamips.h:10:
/opt/local/include/libelf/libelf.h:31:10: fatal error: 'libelf/sys_elf.h' file not found
#include <libelf/sys_elf.h>
         ^
1 error generated.
make[2]: *** [stable/CMakeFiles/nvram_export.dir/__/common/nvram_export.c.o] Error 1
make[1]: *** [stable/CMakeFiles/nvram_export.dir/all] Error 2
make: *** [all] Error 2
Build step 'Execute shell' marked build as failure
SSH: Current build result is [FAILURE], not going to run.
Finished: FAILURE

@Ehlers it seem you successfully compile on OSX which environnement are you using?

I'm using homebrew on OS X 10.9.5

Installation of libelf takes about a second, as homebrew uses precompiled binaries:

/Users/behlers# brew install libelf
==> Downloading https://homebrew.bintray.com/bottles/libelf-0.8.13.mavericks.bot
######################################################################## 100,0%
==> Pouring libelf-0.8.13.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/libelf/0.8.13: 11 files, 264K

WIth homebrew in 10.10:

➤  cmake ..
-- CMAKE_MODULE_PATH=/Users/noplay/code/gns3/dynamips/cmake
-- dependencies - BEGIN
-- ARCH_AMD64=1
-- ARCH_X86=1
-- DYNAMIPS_ARCH=amd64
-- LIBELF_FOUND=TRUE
-- LIBELF_INCLUDE_DIRS=/usr/local/include/libelf
-- LIBELF_LIBRARIES=/usr/local/lib/libelf.a
-- LIBELF_DEFINITIONS=
CMake Error at cmake/utils.cmake:55 (message):
  libelf was found but cannot be used with DYNAMIPS_ARCH=amd64.  Make sure
  the library for the target architecture is installed.  If needed, you can
  set the variables LIBELF_INCLUDE_DIRS and LIBELF_LIBRARIES manually.
Call Stack (most recent call first):
  cmake/dependencies.cmake:146 (bad_arch_library)
  CMakeLists.txt:32 (include)


-- Configuring incomplete, errors occurred!
See also "/Users/noplay/code/gns3/dynamips/build/CMakeFiles/CMakeOutput.log".
See also "/Users/noplay/code/gns3/dynamips/build/CMakeFiles/CMakeError.log".
``` 

What cmake actually does is to compile a test program CheckFunctionExists.c and see if it can be linked. On my system (cmake and libelf from homebrew) it does the equivalent of:

/Users/behlers/dynamips/cmake# cc -DCHECK_FUNCTION_EXISTS=elf_begin -m64 -o xxx /usr/local/Cellar/cmake/3.1.2/share/cmake/Modules/CheckFunctionExists.c /usr/local/lib/libelf.a 
/Users/behlers/dynamips/cmake# 
/Users/behlers/dynamips/cmake# 
/Users/behlers/dynamips/cmake# cc -DCHECK_FUNCTION_EXISTS=elf_begin -m32 -o xxx /usr/local/Cellar/cmake/3.1.2/share/cmake/Modules/CheckFunctionExists.c /usr/local/lib/libelf.a 
ld: warning: ignoring file /usr/local/lib/libelf.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libelf.a
Undefined symbols for architecture i386:
  "_elf_begin", referenced from:
      _main in CheckFunctionExists-aeb4a7.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/Users/behlers/dynamips/cmake# 

It's actually a little but more complex, to see the details have a look into your CMakeError.log

It there is a problem to compile and/or link with libelf you will get the same error message, even if it has nothing to do with the architecture. See analyzing CMakeError.log should give some hints.

So it's work on yosemite when using:
cmake .. -DCMAKE_C_COMPILER=/usr/local/bin/gcc-4.9

Otherwise it's use gcc 4.2

I'm using the default apple compiler clang, don't know how stable dynamips is with that. At least it compiles and successfully starts. But haven't done real tests.

/Users/behlers# cc -v
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

And i got the same error:

Scanning dependencies of target nvram_export
[  1%] Building C object stable/CMakeFiles/nvram_export.dir/__/common/nvram_export.c.o
In file included from /Users/noplay/code/gns3/dynamips/common/dynamips.h:10:0,
                 from /Users/noplay/code/gns3/dynamips/common/nvram_export.c:14:
/usr/local/include/libelf/libelf.h:31:28: fatal error: libelf/sys_elf.h: No such file or directory
 #include <libelf/sys_elf.h>
                            ^
compilation terminated.
make[2]: *** [stable/CMakeFiles/nvram_export.dir/__/common/nvram_export.c.o] Error 1
make[1]: *** [stable/CMakeFiles/nvram_export.dir/all] Error 2
make: *** [all] Error 2

That's strange, sys_elf.h should be there

/Users/behlers# ls /usr/local/include/libelf/
elf_repl.h  gelf.h      libelf.h    nlist.h     sys_elf.h

Yeah it's here :(

It seem LIBELF_INTERNAL should be defined somewhere

Or adding:
+include_directories(include /usr/local/include/)

In CMakeLists.txt solve the issue