Can't find libraries from Linker using clang-newlib

236 views
Skip to first unread message

Yoichiro Tanaka

unread,
Apr 20, 2015, 8:52:37 PM4/20/15
to native-cli...@googlegroups.com
I'm testing a pepper_43 bundle. I know that the NaCl SDK has a new toolchain "clang-newlib" since the pepper_42. My application is using the dependent libraries: libssh2, openssl and glibc-compat. they are included in the naclports. I tried to use these libraries in my application with pepper_43. However, the building failed. It seems that the linker could not find these libraries. In the cases of using other toolchains, the buildings succeeded.

First, I built and installed these libraries to the pepper_43 directory. I think that this was completed successfully.

gclient config --name=src https://chromium.googlesource.com/external/naclports.git@pepper_43
gclient sync
cd src; ./make_all.sh libssh2

[src] ./make_all.sh libssh2
+ set -e
+ TARGETS=libssh2
+ TARGETS=libssh2
+ BUILD_FLAGS=--ignore-disabled
+ export BUILD_FLAGS
+ NACL_ARCH=x86_64
+ TOOLCHAIN=clang-newlib
+ make libssh2
bin/naclports install libssh2 --ignore-disabled
Already installed 'libssh2' [x86_64/clang-newlib/release]
...
+ NACL_ARCH=i686
+ TOOLCHAIN=clang-newlib
+ make libssh2
bin/naclports install libssh2 --ignore-disabled
Already installed 'libssh2' [i686/clang-newlib/release]
...
+ NACL_ARCH=arm
+ TOOLCHAIN=clang-newlib
+ make libssh2
bin/naclports install libssh2 --ignore-disabled
Already installed 'libssh2' [arm/clang-newlib/release]
...
+ BIONIC_TOOLCHAIN='/Applications/nacl/nacl_sdk/pepper_43/toolchain/*_arm_bionic'
++ shopt -s nullglob
++ echo
+ '[' -n '' ']'
+ NACL_ARCH=pnacl
+ TOOLCHAIN=pnacl
+ make libssh2
bin/naclports install libssh2 --ignore-disabled
Already installed 'libssh2' [pnacl/release]
+ '[' -n '' ']'

When I confirm the installed files, the following output can be retrieved:

[pepper_43] find . -name 'libssh2.a' -print
./toolchain/mac_arm_newlib/arm-nacl/usr/lib/libssh2.a
./toolchain/mac_pnacl/arm-nacl/usr/lib/libssh2.a
./toolchain/mac_pnacl/i686-nacl/usr/lib/libssh2.a
./toolchain/mac_pnacl/le32-nacl/usr/lib/libssh2.a
./toolchain/mac_pnacl/x86_64-nacl/usr/lib/libssh2.a
./toolchain/mac_x86_glibc/i686-nacl/usr/lib/libssh2.a
./toolchain/mac_x86_glibc/x86_64-nacl/usr/lib/libssh2.a
./toolchain/mac_x86_newlib/i686-nacl/usr/lib/libssh2.a
./toolchain/mac_x86_newlib/x86_64-nacl/usr/lib/libssh2.a

I guess that the files in the mac_pnacl diretory will be used for the clang-newlib...

Second, I executed the make command to build my application with the clang-newlib. Especially, my Makefile depends on the common.mk file provided by the tools directory of NaCl SDK. The content of my Makefile is the follows:

VALID_TOOLCHAINS := clang-newlib
NACL_SDK_ROOT ?= $(abspath $(CURDIR)/../..)
OUTBASE = ..
include $(NACL_SDK_ROOT)/tools/common.mk
TARGET = sftp
LIBS = ssh2 crypto nacl_io ppapi_cpp ppapi pthread
# CFLAGS = -Wall -std=c++0x
CFLAGS = -Wall -std=gnu++11
SOURCES = foo.cc bar.cc ...
# Build rules generated by macros from common.mk:
$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
# The PNaCl workflow uses both an unstripped and finalized/stripped binary.
# On NaCl, only produce a stripped binary for Release configs (not Debug).
ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring Release,$(CONFIG))))
$(eval $(call LINK_RULE,$(TARGET)_unstripped,$(SOURCES),$(LIBS),$(DEPS)))
$(eval $(call STRIP_RULE,$(TARGET),$(TARGET)_unstripped))
else
$(eval $(call LINK_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS)))
endif
$(eval $(call NMF_RULE,$(TARGET),))

The result of the execution of the make command was "failed". Specifically, Compiling were successfully, but linking was failed with the following output:

[nacl_src] make
LINK ../clang-newlib/Release/sftp_unstripped_x86_32.nexe
/Applications/nacl/nacl_sdk/pepper_43/toolchain/mac_pnacl/bin/../x86_64-nacl/bin/ld: cannot find -lssh2
/Applications/nacl/nacl_sdk/pepper_43/toolchain/mac_pnacl/bin/../x86_64-nacl/bin/ld: cannot find -lcrypto
i686-nacl-clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [../clang-newlib/Release/sftp_unstripped_x86_32.nexe] Error 1

When I changed the toolchain to "newlib" and "pnacl", these were successfully...

I guess that the path for searching library was invalid against using clang-newlib. Should I specify the additional path in my Makefile? Or, is there some bug in the NaCl SDK?

Thank you for your advice.

-Yoichiro

Sam Clegg

unread,
Apr 20, 2015, 10:00:26 PM4/20/15
to native-cli...@googlegroups.com
Hi Yoichiro,

This is known issue with the i686-nacl-clang toolchain:
https://code.google.com/p/nativeclient/issues/detail?id=4108

The naclports build system works around this by adding the
i686-nacl/usr/lib folder to LDFLAGS. You will need to do the same in
your Makefile until we can get this issue resolved in the toolchain.
This issue only effects the i686 compiler so if you make with
TOOLCHAIN=x86_64 it should work fine.

cheers,
sam
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

Yoichiro Tanaka

unread,
Apr 21, 2015, 12:39:30 AM4/21/15
to native-cli...@googlegroups.com
Hi Sam,

Thank you for the quick reply! I understood the issue and
I could recognized the workaround I should do.
I intend to try it. I appreciate it.

-Yoichiro



2015年4月21日火曜日 11時00分26秒 UTC+9 Sam Clegg:

Yoichiro Tanaka

unread,
Apr 21, 2015, 3:51:48 AM4/21/15
to native-cli...@googlegroups.com
I could just build my application with clang-newlib for i686 using the following addition to my Makefile:

ifeq ($(NACL_ARCH),x86_32)
  LDFLAGS = "-L$(NACL_SDK_ROOT)/toolchain/mac_pnacl/i686-nacl/usr/lib"
endif

$ make NACL_ARCH=x86_32; make NACL_ARCH=x86_64; make NACL_ARCH=arm

Thank you for your advice!

-Yoichiro


2015年4月21日火曜日 13時39分30秒 UTC+9 Yoichiro Tanaka:
Reply all
Reply to author
Forward
0 new messages