Link error undefined reference to `dgels_' in Lapack - linux

I followed this below webpage to install ATLAS + Lapack in linux :
http://math-atlas.sourceforge.net/atlas_install/node6.html
bunzip2 -c atlas3.10.1.tar.bz2 | tar xfm - # create SRCdir
mv ATLAS ATLAS3.10.1 # get unique dir name
cd ATLAS3.10.1 # enter SRCdir
mkdir Linux_C2D64SSE3 # create BLDdir
cd Linux_C2D64SSE3 # enter BLDdir
../configure -b 64 -D c -DPentiumCPS=2400 \ # configure command
--prefix=/home/whaley/lib/atlas \ # install dir
--with-netlib-lapack-tarfile=/home/whaley/dload/lapack-3.4.2.tgz
make build # tune & build lib
make check # sanity check correct answer
make ptcheck # sanity check parallel
make time # check if lib is fast
make install # copy libs to install dir
After that , I try to run an sample in
http://www.netlib.org/lapack/lapacke.html
the sample code :
#include <stdio.h>
#include <lapacke.h>
int main (int argc, const char * argv[])
{
double a[5*3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3};
double b[5*2] = {-10,12,14,16,18,-3,14,12,16,16};
lapack_int info,m,n,lda,ldb,nrhs;
int i,j;
m = 5;
n = 3;
nrhs = 2;
lda = 5;
ldb = 5;
info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,a,lda,b,ldb);
for(i=0;i<n;i++)
{
for(j=0;j<nrhs;j++)
{
printf("%lf ",b[i+ldb*j]);
}
printf("\n");
}
return(info);
}
I have found out the build library has no iblapacke.a , so I build this library by myslef
cd lapack-3.4.2
cp make.inc.example make.inc
cd lapacke
make
Then , finally I have the iblapacke.a now , so I compile the sample above by :
g++ test3.cpp liblapacke.a -o test3.exe
I get the following errors :
liblapacke.a(lapacke_dgels_work.o): In function `LAPACKE_dgels_work':
lapacke_dgels_work.c:(.text+0x1dd): undefined reference to `dgels_'
lapacke_dgels_work.c:(.text+0x2b7): undefined reference to `dgels_'
After I google , I have found :
http://www.netlib.org/lapack/explore-html/d7/d3b/group__double_g_esolve.html
Functions/Subroutines
subroutine dgels (TRANS, M, N, NRHS, A, LDA, B, LDB, WORK, LWORK, INFO)
DGELS solves overdetermined or underdetermined systems for GE matrices
There is a function dgels , without underline , and in
http://shtools.ipgp.fr/www/faq.html#l4
I think the underline is added for accident ,
nm -A liblapacke.a |grep "dgels_"
liblapacke.a:lapacke_dgels.o: U LAPACKE_dgels_work
liblapacke.a:lapacke_dgels_work.o: U LAPACKE_dge_trans
liblapacke.a:lapacke_dgels_work.o:0000000000000000 T LAPACKE_dgels_work
liblapacke.a:lapacke_dgels_work.o: U LAPACKE_xerbla
liblapacke.a:lapacke_dgels_work.o: U dgels_
liblapacke.a:lapacke_dgels_work.o: U free
liblapacke.a:lapacke_dgels_work.o: U malloc
I think I should try to not avoid underline like build "dgels" not to "dgels" while build liblapack.a ,means I should change something build Lapack and ATLAS ,
just don't know how to do it ....Any suggestion is appreciated !!
Update : http://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/c_bindings.htm
I have no idea if related , -Ddgels=dgels_ is added , the same link error !!

see:
http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=12&t=3336
for example:
gcc LinearEquation.c -Ilapack-3.5.0/lapacke/include/ -Llapack-3.5.0 -llapacke -llapack -lrefblas -lgfortran -o LinearEquation
the order of lapacke > lapack > refblas is important... also if you don't want to use the double step gcc gfortran, use -lgfortran

I had the exact same problem. You need to do it as follows:
gcc(or g++) -c -O3 -I ../include -o test.o test.c
and then
gfortran test.o ../liblapacke.a ../liblapack.a ../blas.a -o test.exe
You can then run it like so:
./test.exe
Basically, you need to follow the gcc compile with a gfortran compile. The -c option in the first command forces gcc to skip the linker. gfortran is then used to link the libraries.
You can learn more by looking at the makefile for the examples provided with LAPACKE.

I had the same problem (using g++), but fixed my problems by adding a -lblas and -lgfortran.

To resolve the issue, here are the steps I have done.
sudo apt-get install libblas-dev liblapack-dev gfortran
linking a -lblas and -lgfortran when it runs

Related

raylib :: Making the barest code required for a blank window

Greetings
I'm very new to C. I would like to know the most minimal amount of steps/code for making a basic window using raylib. I'm using Linux and have followed the steps on github https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux, but I honestly don't know where to begin to build my own project. Is cmake or make required for a basic window like in the example: core_basic_window.c, that I'm able to compile (using the instructions from github, but I'm not sure how to modify/simply the code for my own project). Thank you : )
I've tried to copy and past this code from the github pull/project/directory and run gcc on it but I get error messages:
// Filename: core_basic_window.c
#include "raylib.h"
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
Couldn't compile:
########-ThinkPad-T430:~/Documents/c/bin/tmp$ gcc core_basic_window.c
/usr/bin/ld: /tmp/ccB5BYug.o: in function `main':
blah.c:(.text+0x2d): undefined reference to `InitWindow'
/usr/bin/ld: blah.c:(.text+0x37): undefined reference to `SetTargetFPS'
/usr/bin/ld: blah.c:(.text+0x3e): undefined reference to `BeginDrawing'
/usr/bin/ld: blah.c:(.text+0x65): undefined reference to `ClearBackground'
/usr/bin/ld: blah.c:(.text+0xa6): undefined reference to `DrawText'
/usr/bin/ld: blah.c:(.text+0xab): undefined reference to `EndDrawing'
/usr/bin/ld: blah.c:(.text+0xb0): undefined reference to `WindowShouldClose'
/usr/bin/ld: blah.c:(.text+0xbc): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
You didn't like your libraries right. If you are using the Notepad++ option then:
Create a Folder, and create a main.cpp/.c file. ->
Navigate to the Raylib download folder, extracted of course, and click npp->then click notepad++.exe
In notepad++ click file->Open (or Ctrl-O) then navigate to the folder you created for your project-> Write code then click F6 to run. That should be simple to follow instructions.
Compiler Flags (for GCC)
echo > Setup required Environment
echo -------------------------------------
SET RAYLIB_PATH=C:\raylib\raylib
SET COMPILER_PATH=C:\raylib\w64devkit\bin
ENV_SET PATH=$(COMPILER_PATH)
SET CC=gcc
SET CFLAGS=$(RAYLIB_PATH)\src\raylib.rc.data -s -static -Os -std=c99 -Wall -I$(RAYLIB_PATH)\src -Iexternal -DPLATFORM_DESKTOP
SET LDFLAGS=-lraylib -lopengl32 -lgdi32 -lwinmm
cd $(CURRENT_DIRECTORY)
echo
echo > Clean latest build
echo ------------------------
cmd /c IF EXIST $(NAME_PART).exe del /F $(NAME_PART).exe
echo
echo > Saving Current File
echo -------------------------
npp_save
echo
echo > Compile program
echo -----------------------
$(CC) -o $(NAME_PART).exe $(FILE_NAME) $(CFLAGS) $(LDFLAGS)
echo
echo > Reset Environment
echo --------------------------
ENV_UNSET PATH
echo
echo > Execute program
echo -----------------------
cmd /c IF EXIST $(NAME_PART).exe $(NAME_PART).exe
If you put this into a main.bat file or something it should give you a raylib runtime.

ERROR: Installing a Fortran library on Ubuntu 12.04

I have been trying to install the library with a Makefile written in Fortran using the latest gfortran version.
The instructions are:
M-LIB is provided with a very bare-bones makefile, which should be
modified for your Fortran compiler. To compile, run make in the src
directory. This creates library lib.a and executable m-lib.
The Makefile is:
FC = gfortran
FCFLAGS = -O3
AR = ar
ARFLAGS = -cru
LDFLAGS =
LIBRARY = lib.a
PROGRAM = m-lib
PROGOBJECTS = LIBTEST.o EOS.o
LIBOBJECTS = ADATA.o \
ADEBY.o \
AE2PH.o \
AEHPP.o \
AEI3.o \
AZRTR.o
%.o: %.f
$(FC) -c $(FCFLAGS) $<
default: $(PROGRAM)
$(LIBRARY): $(LIBOBJECTS)
rm -f $(LIBRARY)
$(AR) -cr $(LIBRARY) $(LIBOBJECTS)
$(PROGRAM): $(PROGOBJECTS) $(LIBRARY)
$(FC) $(FCFLAGS) -o $(PROGRAM) $(PROGOBJECTS) $(LIBRARY)
install:
cp ../input/q_.input ../example/m-lib.INPUT
cp ./m-lib ../example/m-lib
clean:
rm -f $(LIBOBJECTS) $(PROGOBJECTS)
allclean:
rm -f $(PROGRAM) $(LIBRARY)
make clean
And I get this error:
enter codegfortran -c -O3 LIBTEST.f
LIBTEST.f:36.26:
allocate (character(arglen) :: arg)
1
Error: Variable 'arglen' cannot appear in the expression at (1)
LIBTEST.f:99.72:
DO 10 I=1,NDENS
1
Warning: DO loop at (1) will be executed zero times
LIBTEST.f:104.72:
DO 20 J=1,NTEMP
1
Warning: DO loop at (1) will be executed zero times
make: *** [LIBTEST.o] Error 1
¿Any idea what is wrong?
EDIT
This is source code of EOS.o:
SUBROUTINE EOS(TEMP,TEMP0,P,RHO,E,M)
IMPLICIT REAL*8 (A-H,O-Z)
TEMP=TEMP0
IT=0
10 CONTINUE
IT=IT+1
IF(IT.GT.50) STOP 'TOO MANY ITERATIONS--EOS'
CALL ADEBY (TEMP,RHO,P,ETRIAL,S,CV,DPDT,DPDR,FKROS,CS,KPA,M)
IF (ABS(E-ETRIAL) .LT. 1.0D-9*E) RETURN
TEMP=TEMP+(E-ETRIAL)/CV
GOTO 10
END
This is first lines of the source code of LIBTEST.o:
PROGRAM LIBTEST
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
INTEGER STYLE
PARAMETER (NDENS=0)
PARAMETER (NTEMP=0)
DIMENSION IZETL(21)
COMMON /FILEOS/ KLST, KINP
COMMON /ANGELX/ W,Y,ALFA,BETA,DADT,DADR,DBDT,ZZ,ET,
& SN,CVN,EN,PN,PM,EM,SM,CVM,EC,PC,RHO0,RHO00,ZVIB,
& SMLT,CVMLT,EMLT,PMLT,H1,H2
COMMON /ANEEL/ TEVX,RHOX,ABARX,ZBARM,T32X,FNX
& ,PE,EE,SE,CVE,DPTE,DPRE
& ,NMATSX,IIZX
COMMON /ANEDIS/ GAMMA,PSI,THETA
PARAMETER (MATBUF=64)
COMMON /ANESQT/ SQTS(MATBUF),IPSQTS
DIMENSION RHO(NDENS),TEMP(NTEMP),HISTDENS(100),HISTPRESS(100)
DIMENSION HISTDPDR(100)
DIMENSION TARR(2000)
DIMENSION DARR(2000)
DIMENSION PARR(2000,2000)
DIMENSION SARR(2000,2000)
DIMENSION EARR(2000,2000)
DIMENSION CSARR(2000,2000)
DIMENSION CVARR(2000,2000)
DIMENSION ZKARR(2000,2000)
C
CSTS ADDS --help, --no_table, and file checks
character(:), allocatable :: arg
integer arglen, stat
logical file_exists
call get_command_argument(number=1, length=arglen) ! Assume for simplicity success
allocate (character(arglen) :: arg)
call get_command_argument(number=1, value=arg, status=stat)
IF (arg.NE.'--quiet') THEN
write(*,9020)
write(*,9021)
write(*,9022)
write(*,9023)
(...)

Linking library (from assembly files) with main.c in Makefile

Im passionate about assembly and wanted to start coding from home on linux instead of mac I usually use.
I really struggle for 4 days about this issue.
you can find my makefile and clone repository at the following url:
<code>NAME = libfts.a
ASM_FILES = ft_isascii \
OS := $(shell uname)
ifeq ($(OS), Darwin)
ASM_COMPILER = ~/.brew/bin/nasm -f macho64 -g
else
ASM_COMPILER = nasm -f elf64 -g
endif
ASM_SRC_DIR = srcs/
ASM_OBJ_DIR_NAME = obj
ASM_OBJ_DIR = $(ASM_OBJ_DIR_NAME)/
ASM_OBJ := $(addsuffix .o,$(ASM_FILES))
ASM_OBJ := $(addprefix $(ASM_OBJ_DIR),$(ASM_OBJ))
TEST = maintest.out
TEST_FILES = maintest
C_COMPILER = clang -Wall -Werror -Wextra -O3
TEST_DIR_NAME = test
TEST_DIR = $(TEST_DIR_NAME)/
TEST_OBJ := $(addsuffix .o,$(TEST_FILES))
TEST_OBJ := $(addprefix $(TEST_DIR),$(TEST_OBJ))
OBJ_PATHS := $(ASM_OBJ) $(TEST_OBJ)
all: $(NAME)
$(NAME): $(ASM_OBJ)
ar rc $(NAME) $(ASM_OBJ)
test: re $(TEST_OBJ)
$(C_COMPILER) -L. $(NAME) $(TEST_OBJ) -o $(TEST)
$(ASM_OBJ): $(ASM_OBJ_DIR)%.o: $(ASM_SRC_DIR)%.s
#/bin/mkdir -p $(ASM_OBJ_DIR)
$(ASM_COMPILER) $< -o $#
$(TEST_OBJ): $(TEST_DIR)%.o: $(TEST_DIR)%.c
$(C_COMPILER) -c -I. $< -o $#
clean:
-/bin/rm -f $(OBJ_PATHS)
/usr/bin/find . -name "$(ASM_OBJ_DIR_NAME)" -maxdepth 1 -type d -empty -delete
fclean: clean
-/bin/rm -f $(NAME)
-/bin/rm -f $(TEST)
re: fclean all
.PHONY: all clean fclean re
I have this error message when I try "make test" on the linux:
test/maintest.o: In function `main':
test/maintest.c:(.text+0x33): undefined reference to `ft_isascii'
undefined reference to etc.
.h content:
#ifndef _LIBFTS
# define _LIBFTS
#include <stddef.h>
int ft_isascii(int c);
#endif
ft_isascii.s content:
global _ft_isascii
section .text
_ft_isascii: ; int ft_isascii
and edi, 0xffffff80 ; mask with the 128 firsts bits left to 0 as ASCII range from 0 to 7f in hexa (just below 80)
sete al ; SETE sets AL to 1 if above condition code means "equal", otherwise it sets AL to 0.
movzx eax, al
ret
I would REALLY be thanksful for any tips to solve this issue...
Regards,
There are two problems to be fixed:
First, on ELF targets (most Unixes except macOS), C functions are not decorated with an underscore. To fix your code, remove the leading underscore from all symbols. Make sure to remove it everywhere.
Second, the linker when looking at an archive (.a file) only picks files it needs right now to satisfy dependencies. So when you pass the archive before maintest.o, the linker doesn't take anything from the archive at all as it doesn't need any ft_... symbols at that point. These symbols are only needed once the linker has seen maintest.o. To fix this issue, move the $(NAME) operand to after $(TEST_OBJ). As a general rule of thumb, always place libraries after object files on the linker command line.
On macOS, you won't observe this problem because they use lld, the LLVM linker, which is a bit unconventional in that it defers the choice which objects to take out of archives until it has looked at the symbol tables of all operands, making your actually broken invocation work. Don't depend on this behaviour, please.

PNaCl & gtest—pnacl-ld: Incompatible object file (X8664 != X8632)

I'm a newbie at this,Please help me ...T_T...
Recently I was building pthreadpool(required by NNPACK) with ninja on my Ubuntu 14.04 64bit.
It requires Google PNaCl(Portable Native Client) and Google Test,and I installed both.
After I run python ./configure.py in pthreadpool root dir,
it generated a file build.ninja:
pnacl_toolchain_dir = $nacl_sdk_dir/toolchain/linux_pnacl
pnacl_cc = $pnacl_toolchain_dir/bin/pnacl-clang
pnacl_cxx = $pnacl_toolchain_dir/bin/pnacl-clang++
pnacl_ar = $pnacl_toolchain_dir/bin/pnacl-ar
pnacl_finalize = $pnacl_toolchain_dir/bin/pnacl-finalize
pnacl_translate = $pnacl_toolchain_dir/bin/pnacl-translate
pnacl_sel_ldr = $nacl_sdk_dir/tools/sel_ldr.py
cflags = -std=gnu11
cxxflags = -std=gnu++11
optflags = -O3
rule cc
command = $pnacl_cc -o $out -c $in -MMD -MF $out.d $optflags $cflags $
$includes
description = CC[PNaCl] $descpath
depfile = $out.d
deps = gcc
rule cxx
command = $pnacl_cxx -o $out -c $in -MMD -MF $out.d $optflags $cxxflags $
$includes
description = CXX[PNaCl] $descpath
depfile = $out.d
deps = gcc
rule ccld
command = $pnacl_cc -o $out $in $libs $libdirs $ldflags
description = CCLD[PNaCl] $descpath
rule cxxld
command = $pnacl_cxx -o $out $in $libs $libdirs $ldflags
description = CXXLD[PNaCl] $descpath
rule ar
command = $pnacl_ar rcs $out $in
description = AR[PNaCl] $descpath
rule finalize
command = $pnacl_finalize $finflags -o $out $in
description = FINALIZE[PNaCl] $descpath
rule translate
command = $pnacl_translate -arch $arch -o $out $in
description = TRANSLATE[PNaCl] $descpath
rule run
command = $pnacl_sel_ldr $in
description = RUN[PNaCl] $descpath
pool = console
rule install
command = install -m $mode $in $out
description = INSTALL $out
build /home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc: cc $
/home/rokim/NNPACK/third-party/pthreadpool/src/pthreadpool.c
descpath = pthreadpool.c
includes = -I$nacl_sdk_dir/include $
-I/home/rokim/NNPACK/third-party/pthreadpool/include $
-I/home/rokim/NNPACK/third-party/pthreadpool/src
build $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/libpthreadpool.a: $
ar /home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc
descpath = libpthreadpool.a
build $
/home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.cc.bc: $
cxx /home/rokim/NNPACK/third-party/pthreadpool/test/pthreadpool.cc
descpath = pthreadpool.cc
includes = -I$nacl_sdk_dir/include $
-I/home/rokim/NNPACK/third-party/pthreadpool/include $
-I/home/rokim/NNPACK/third-party/pthreadpool/src
build /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc: $
cxxld /home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc $
/home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.cc.bc
libs = -lgtest
libdirs = -L$nacl_sdk_dir/lib/pnacl/Release
descpath = pthreadpool.bc
build $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/pthreadpool.pexe: $
finalize $
/home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc
descpath = pthreadpool.pexe
build $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/pthreadpool.nexe: $
translate $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/pthreadpool.pexe
arch = x86_64
descpath = pthreadpool.pexe
build test: run $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/pthreadpool.nexe
descpath = pthreadpool.nexe
default $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/libpthreadpool.a $
/home/rokim/NNPACK/third-party/pthreadpool/artifacts/pthreadpool.nexe
build /usr/local/include/pthreadpool.h: install $
/home/rokim/NNPACK/third-party/pthreadpool/include/pthreadpool.h
mode = 0644
build /usr/local/lib/libpthreadpool.a: install $
/home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc
mode = 0644
build install: phony /usr/local/include/pthreadpool.h $
/usr/local/lib/libpthreadpool.a
But when I run the command ninja,there came the error:
[4/6] CXXLD[PNaCl] pthreadpool.bc
FAILED: /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc
/toolchain/linux_pnacl/bin/pnacl-clang++ -o /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc /home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.cc.bc -lgtest -L/lib/pnacl/Release
pnacl-ld: Cannot find '-lgtest'
ninja: build stopped: subcommand failed.
I thought it may be the path problem,so I put libgtest.a and libgtest_main.a (Generated from Google Test) in /usr/lib/gtest and modified the build.ninja:
libs = -L/usr/lib/gtest -lgtest_main -lgtest
It seems ninja found the lib files, but there came the error:
[1/3] CXXLD[PNaCl] pthreadpool.bc
FAILED: /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc
/toolchain/linux_pnacl/bin/pnacl-clang++ -o /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.bc /home/rokim/NNPACK/third-party/pthreadpool/build/pthreadpool.c.bc /home/rokim/NNPACK/third-party/pthreadpool/build/test/pthreadpool.cc.bc -L/usr/lib/gtest -lgtest_main -lgtest -L/lib/pnacl/Release
pnacl-ld: /usr/lib/gtest/libgtest_main.a: Incompatible object file (X8664 != X8632)
ninja: build stopped: subcommand failed.
I believe the lib files are good since I tried to use g++ to compile a test.cpp:
g++ test.cpp -lgtest_main -lgtest -lpthread
And it worked.
So I thought it might be something wrong about pnacl or the way I use it.I googled the 32bit 64bit incompatible problem about pnacl and gtest but I got nothing. Now I have totally no idea about what to do since I'm a newbie at this...
So please, any help, idea or suggestions would be greatly appriciate!
For Google PNaCl,I downloaded the nacl_sdk.zip and unziped it to /home/rokim/nacl_sdk and I got sdk_tools and pepper_49 up to date.
For Google Test,I run sudo apt-get install libgtest-dev . After cmake and make I got libgtest.a and libgtest_main.a then I put them into /usr/lib and /usr/local/lib.The gtest include file are put into /usr/include and usr/local/include.
You can't use libgtest from the host system with the NaCl compilers. Everything you link has to be built with the same (NaCl) compiler. So you want to build libgtest with pnacl-clang, and link that with your other PNaCl build.

Doubts in running an Rcpp example

I'm trying to reproduce the examples of "Seamless R and C++ Integration with Rcpp" book, but some codes are not running. Specifically, it is on chapter 5, Section 5.2.3 and the code follows above:
#ifndef _mypackage_RCPP_HELLO_WORLD_H
#define _mypackage_RCPP_HELLO_WORLD_H
#include <Rcpp.h>
/*
* note : RcppExport is an alias to 'extern "C"' defined by Rcpp.
*
* It gives C calling convention to the rcpp_hello_world
* function so that it can be called from .Call in R.
* Otherwise, the C++ compiler mangles the
* name of the functioand .Call can’t find it.
* It is only useful to use RcppExport when the function
* is intended to be called by .Call. See the thread
* http://thread.gmane.org/gmane.comp.lang.r.rcpp/649/focus=672
* on Rcpp-devel for a misuse of RcppExport 19
*/
RcppExport SEXP rcpp_hello_world();
#endif
and the next is
#include "rcpp_hello_world.h"
SEXP rcpp_hello_world() {
using namespace Rcpp;
CharacterVector x = CharacterVector::create( "foo", "bar" ) ;
NumericVector y = NumericVector::create( 0.0, 1.0 ) ;
List z = List::create( x, y ) ;
return z ;
}
The error showed by R is
Error in .Call("rcpp_hello_world", PACKAGE = "mypackage") :
"rcpp_hello_world" not available for .Call() for package "mypackage"
Have anyone faced a problem like this?
Thanks in advance!
When I try to tip
R CMD check mypackage_1.0.tar.gz
I got an error like this
* using log directory ‘/Users/Marcos/Downloads/mypackage.Rcheck’
* using R version 3.0.2 (2013-09-25)
* using platform: x86_64-apple-darwin10.8.0 (64-bit)
* using session charset: UTF-8
* checking for file ‘mypackage/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘mypackage’ version ‘1.0’
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘mypackage’ can be installed ... ERROR
Installation failed.
See ‘/Users/Marcos/Downloads/mypackage.Rcheck/00install.out’ for details.
In the file 00install.out, the first error is
* installing *source* package ‘mypackage’ ...
** libs
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -fPIC -mtune=core2 -g -O2 -c RcppExports.cpp -o RcppExports.o
In file included from /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/RcppCommon.h:28,
from /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp.h:27,
from RcppExports.cpp:4:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:93:17: error: cmath: No such file or directory
And then, I just got error messages.
Go to the terminal:
R CMD build mypackage
R CMD check mypackage_1.0.tar.gz
R CMD install mypackage
and in R:
library(mypackage)
rcpp_hello_world()
[[1]]
[1] "foo" "bar"
[[2]]
[1] 0 1
Now, I don't understand where to use the code written in "Listing 5.4", Do I need to write it or this is created automatically?
This example (and chapter) discusses how to build (and load) an entire package, here called mypackage.
Did you actually create, compile and load mypackage?
This works, as we do this each and every time the unit tests run.
Edit: Here is a full log for you
R> library(Rcpp)
R> Rcpp.package.skeleton("mypackage") ## page 66, Section 5.2.1
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './mypackage/Read-and-delete-me'.
Adding Rcpp settings
>> added Depends: Rcpp
>> added LinkingTo: Rcpp
>> added useDynLib directive to NAMESPACE
>> added Makevars file with Rcpp settings
>> added Makevars.win file with Rcpp settings
>> added example src file using Rcpp attributes
>> compiled Rcpp attributes
>> added Rd file for rcpp_hello_world
R>
We can now build the tarball:
R> system("R CMD build mypackage")
* checking for file 'mypackage/DESCRIPTION' ... OK
* preparing 'mypackage':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'mypackage_1.0.tar.gz'
R>
then we can install it: (and I am doing that on a Windows machine for a change)
R> system("R CMD INSTALL mypackage_1.0.tar.gz")
* installing to library 'c:/opt/R-library'
* installing *source* package 'mypackage' ...
** libs
*** arch - i386
g++ -m32 -I"c:/opt/R-CURR~1/include" -DNDEBUG -I"c:/opt/R-library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
g++ -m32 -I"c:/opt/R-CURR~1/include" -DNDEBUG -I"c:/opt/R-library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -m32 -shared -s -static-libgcc -o mypackage.dll tmp.def RcppExports.o rcpp_hello_world.o c:/opt/R-library/Rcpp/lib/i386/libRcpp.a -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -Lc:/opt/R-CURR~1/bin/i386 -lR
installing to c:/opt/R-library/mypackage/libs/i386
*** arch - x64
g++ -m64 -I"c:/opt/R-CURR~1/include" -DNDEBUG -I"c:/opt/R-library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
g++ -m64 -I"c:/opt/R-CURR~1/include" -DNDEBUG -I"c:/opt/R-library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -m64 -shared -s -static-libgcc -o mypackage.dll tmp.def RcppExports.o rcpp_hello_world.o c:/opt/R-library/Rcpp/lib/x64/libRcpp.a -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -Lc:/opt/R-CURR~1/bin/x64 -lR
installing to c:/opt/R-library/mypackage/libs/x64
** R
** preparing package for lazy loading
** help
Warning: C:/Users/deddelbuettel/AppData/Local/Temp/RtmpaiaZVk/R.INSTALL65481db46d2b/mypackage/man/mypackage-package.Rd:30: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (mypackage)
R>
after which we can load and run it:
R> library(mypackage)
R> rcpp_hello_world()
[[1]]
[1] "foo" "bar"
[[2]]
[1] 0 1
R>
and finally remove it as it has no real use case besides demonstrating these mechanics:
R> remove.packages("mypackage")
Removing package from ‘c:/opt/R-library’
(as ‘lib’ is unspecified)
R>

Resources