Making libtool use another file/directory pattern - libtool

How to make libtool don't use (in compile mode) .libs folder for generated PIC object files but another one or even change the name of PIC file, for example: object-file.lo, object-file.o, object-file-pic.o -> these three in one folder.
Standard procedure:
$ libtool --mode=compile gcc -O -o call.o -c called.c
libtool: compile: gcc -O -c called.c -fPIC -DPIC -o .libs/call.o
libtool: compile: gcc -O -c called.c -o call.o >/dev/null 2>&1

Related

Link clang++ modules: Function exported using C++20 modules is not visible (clang++): Cannot compile executable file that uses module

I am exporting a function in the following C++20 module. Although the main program can import the module, but it cannot see the exported function:
f1.hpp
export module f1_module;
export void f1() {
}
f1_demo.cpp
import f1_module;
int main() {
f1();
return 0;
}
The build script is:
#!/bin/bash
mkdir -p ./target
FLAGS="-std=c++20 -stdlib=libc++ -fmodules -fbuiltin-module-map"
clang++ $FLAGS \
-fprebuilt-module-path=./target \
-Xclang -emit-module-interface \
-c \
f1.hpp \
-o ./target/f1.module.o
clang++ $FLAGS \
-fprebuilt-module-path=./target \
-fmodule-file=f1_module=./target/f1.module.o \
f1_demo.cpp \
-o ./target/f1_demo.o
The output error: bash build.bash:
ld: error: undefined symbol: f1()
>>> referenced by f1_demo.cpp
>>> /tmp/f1_demo-286314.o:(main)
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
The exported function f1() is not visible in the main program. How to make it work?
I can provide the output to -v.
I am running above build script in conanio/clang14 docker container:
docker run -it --rm -v $(pwd):/sosi conanio/clang14-ubuntu16.04:latest bash
Update: Cannot link
I tried #DavisHerring 's suggestion, adding -c to the second command, however, it does not generate executable. What I have is a regular object file, and a compiled module file. (The outcome of of -c is not executable). But I need an executable: I cannot link them. When tried to link using clang++, the problem is about linking:
I cannot link an object file with a compiled module file:
clang++ $FLAGS \
-Xclang -emit-module-interface \
-c \
f1_module.cpp \
-o ./target/f1_module.o
clang++ $FLAGS \
-fmodule-file=f1_module=./target/f1_module.o \
-c \
f1_demo.cpp \
-o ./target/f1_demo.o
clang \
-v \
./target/f1_module.o \
./target/f1_demo.o \
-o ./target/exe.o
output:
"/usr/local/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ./target/exe.e /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/local/lib/clang/14.0.0/lib/linux/clang_rt.crtbegin-x86_64.o -L/usr/local/bin/../lib/gcc/x86_64-linux-gnu/10.3.0 -L/usr/local/bin/../lib/gcc/x86_64-linux-gnu/10.3.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/local/bin/../lib -L/usr/local/bin/../lib64 -L/lib -L/usr/lib ./target/f1_module.module ./target/f1_demo.o /usr/local/lib/clang/14.0.0/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -l:libllvm-unwind.so --no-as-needed -lc /usr/local/lib/clang/14.0.0/lib/linux/libclang_rt.builtins-x86_64.a --as-needed -l:libllvm-unwind.so --no-as-needed /usr/local/lib/clang/14.0.0/lib/linux/clang_rt.crtend-x86_64.o /usr/lib/x86_64-linux-gnu/crtn.o
followed by error: unclosed quote
ld: error: ./target/f1_module.o:1427: unclosed quote
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
Note: I am running it on MacBook M1 (arm64) with MacOS Monterey 12.4 and run clang++ via Docker 4.9.1 ( Engine: 20.10.16 ).
You want to compile a module twice. Once to emit a module interface file (which should not have the .o suffix BTW; the customary suffix is .pcm, for "precompiled module") and once to emit an object file (with the customary .o suffix).
clang++ -std=c++20 -c f1_module.cpp -o target/f1_module.o # plain old object
clang++ -std=c++20 -Xclang -emit-module-interface \
-c f1_module.cpp -o target/f1_module.pcm # module interface
Now your module (consisting of two files) is ready, you can use it.
You need to compile the main file against the .pcm file and link the resulting objects against the .o file to produce an executable.
clang++ -std=c++20 -fprebuilt-module-path=./target \
-c f1_demo.cpp -o target/f1_demo.o
clang++ -std=c++20 target/f1_demo.o target/f1_module.o -o target/f1.exe
This is not strictly necessary. With clang, the precompiled module can be used as an object file. The linker however won't recognize it, so clang will need to convert .pcm to .o and feed the temporary .o to the linker, each time you link. This is somewhat of a waste so you may want to eliminate this conversion step by building a separate .o file as above. If you choose not to, you still need to mention the module file on the link line. The simplified process is like this:
clang++ -std=c++20 -Xclang -emit-module-interface \
-c f1_module.cpp -o target/f1_module.pcm # compile module once
clang++ -std=c++20 -fprebuilt-module-path=./target \
-c f1_demo.cpp -o target/f1_demo.o # compile main just as before
clang++ -std=c++20 target/f1_demo.o target/f1_module.pcm \
-o target/f1.exe # mention .pcm explicitly
As far as I know (and I don't know very much), there is currently no way to have clang find out automatically which modules to link against.

install_driver(mysql) failed: Can't locate DBD/mysql.pm in #INC ... Trouble connecting to mysql database from perl script

I am trying to use MAMP to develop locally but my perl scripts are failing to connect to my mysql database. When I review the apache log I see "install_driver(mysql) failed: Can't locate DBD/mysql.pm in #INC".
When I run > which perl I get the location of my perl installation and have added that to the perl path in my MAMP's config file.
I have also tried to install DMD::MySql using
cpan[1]> install DBD::mysql
But it fails in the end. I have included the log for the cpan installation process below. I'm hoping that someone has an idea for me.
I am pretty new with this stuff and have been trying to piece my way through for a little while now.
Any help that someone might have would be much appreciated
Thanks
****cpan log****
Checking if your kit is complete...
Looks good
Using DBI 1.636 (for perl 5.016000 on darwin-2level) installed in /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI/
Writing Makefile for DBD::mysql
Wide character in print at /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/MakeMaker.pm line 1028.
Wide character in print at /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/MakeMaker.pm line 1028.
Writing MYMETA.yml and MYMETA.json
cp lib/DBD/mysql.pm blib/lib/DBD/mysql.pm
cp lib/DBD/mysql/GetInfo.pm blib/lib/DBD/mysql/GetInfo.pm
cp lib/DBD/mysql/INSTALL.pod blib/lib/DBD/mysql/INSTALL.pod
cp lib/Bundle/DBD/mysql.pm blib/lib/Bundle/DBD/mysql.pm
cc -c -I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI -I/usr/local/Cellar/mysql/5.7.14/include/mysql -fno-omit-frame-pointer -DDBD_MYSQL_WITH_SSL -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3 -DVERSION=\"4.040\" -DXS_VERSION=\"4.040\" "-I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level/CORE" dbdimp.c
/Users/archie/perl5/perlbrew/perls/perl-5.16.0/bin/perl -p -e "s/~DRIVER~/mysql/g" /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI/Driver.xst > mysql.xsi
/Users/archie/perl5/perlbrew/perls/perl-5.16.0/bin/perl /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/xsubpp -typemap /Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/ExtUtils/typemap mysql.xs > mysql.xsc && mv mysql.xsc mysql.c
Warning: duplicate function definition 'do' detected in mysql.xs, line 249
Warning: duplicate function definition 'rows' detected in mysql.xs, line 673
cc -c -I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBI -I/usr/local/Cellar/mysql/5.7.14/include/mysql -fno-omit-frame-pointer -DDBD_MYSQL_WITH_SSL -DDBD_MYSQL_INSERT_ID_IS_GOOD -g -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -O3 -DVERSION=\"4.040\" -DXS_VERSION=\"4.040\" "-I/Users/archie/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level/CORE" mysql.c
Running Mkbootstrap for DBD::mysql ()
chmod 644 mysql.bs
rm -f blib/arch/auto/DBD/mysql/mysql.bundle
LD_RUN_PATH="/usr/local/Cellar/mysql/5.7.14/lib:/usr/lib" env MACOSX_DEPLOYMENT_TARGET=10.3 cc -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector dbdimp.o mysql.o -o blib/arch/auto/DBD/mysql/mysql.bundle \
-L/usr/local/Cellar/mysql/5.7.14/lib -lmysqlclient -lssl -lcrypto \
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [blib/arch/auto/DBD/mysql/mysql.bundle] Error 1
MICHIELB/DBD-mysql-4.040.tar.gz
/usr/bin/make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
MICHIELB/DBD-mysql-4.040.tar.gz : make NO
make is reporting a missing library (ssl). You have to install ssl libraries first.
Or you may try to install and use DBD::mysqlPP

crosstool-ng -- stdio.h: No such file or directory

I would like to cross compile a simple program that uses libncurses on my x86_64. Target system is MIPS.
My crosstool-ng-1.20 build went fine (with sample mips-unknown-elf)
However, a simple hello world ends badly.
#include <stdio.h>
int main(void)
{
printf("OH HAI.\n");
return 0;
}
--
x86host:~/toolchain$ mips-unknown-elf-gcc -o hello hello.c
hello.c:1:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
I'm clearly doing something terribly wrong here, but where do i start?
[Edit]
Thank you markgz. Codesourcery is exactly what i needed.
mips-linux-gnu-gcc.exe -static -o helloStatic hello.c
Proof of concept complete. Now off to compile my ncurses program.
[Switch:/]$ file /mnt/sd3/user/helloStatic
/mnt/sd3/user/helloStatic: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1,
statically linked, for GNU/Linux 2.6.16, with unknown capability
0x41000000 = 0xf676e75, not stripped
[Switch:/]$ uname -a
Linux Switch 2.6.32.59-cavium-octeon2.cge-cavium-octeon #1
SMP PREEMPT Fri May 10 11:48:14 PDT 2013 mips64 GNU/Linux
[Switch:/]$ /mnt/sd3/user/helloStatic
HOLIDAYS ARE COMING.
You probably needed to build mips-linux-elf-gcc. Are you sure your MIPS target system is configured as big-endian?
Anyway, you can avoid all these problems by downloading the free Mentor/Codesourcery MIPS gnu/gcc cross compilation tool chain from here. This toolchain is available for both Windows and Linux.
root#x86host:~/ncurses-5.9-20141101# export CC=mips-linux-gnu-gcc
root#x86host:~/ncurses-5.9-20141101# ./configure --target=mips-linux-gnu --host=mips-linux-gnu
[..]
root#x86host:~/ncurses-5.9-20141101# make
Then, i copied over a few headers from /usr/include/ to make these go away:
root#x86host:~/ninvaders-0.1.1# make
In file included from ./ncurses.h:1685:0,
from view.h:25,
from view.c:25:
./unctrl.h:54:20: fatal error: curses.h: No such file or directory
#include <curses.h>
^
compilation terminated.
make: *** [view.o] Error 1
root#x86host:~/ninvaders-0.1.1# make
mips-linux-gnu-gcc -static -c -I. -O -Wall globals.c
mips-linux-gnu-gcc -static -c -I. -O -Wall view.c
mips-linux-gnu-gcc -static -c -I. -O -Wall aliens.c
mips-linux-gnu-gcc -static -c -I. -O -Wall ufo.c
mips-linux-gnu-gcc -static -c -I. -O -Wall player.c
mips-linux-gnu-gcc -static -c -I. -O -Wall nInvaders.c
mips-linux-gnu-gcc -static -L /root/ncurses-5.9-20141101/lib -onInvaders globals.o view.o aliens.o ufo.o player.o nInvaders.o -lncurses
root#x86host:~/ninvaders-0.1.1# ls -l nInvaders
-rwxr-xr-x 1 root root 933003 Nov 6 16:18 nInvaders
root#x86host:~/ninvaders-0.1.1# mv nInvaders nInvaders_IOSXE_MIPS
For future googlers, Makefile is:
CC=mips-linux-gnu-gcc -static
CFLAGS=-O -Wall
LIBS=-lncurses
LDFLAGS=-L /root/ncurses-5.9-20141101/lib
CFILES=globals.c view.c aliens.c ufo.c player.c nInvaders.c
HFILES=globals.h view.h aliens.h ufo.h player.h nInvaders.h
OFILES=globals.o view.o aliens.o ufo.o player.o nInvaders.o
all: nInvaders
nInvaders: $(OFILES) $(HFILES)
$(CC) $(LDFLAGS) -o$# $(OFILES) $(LIBS)
.c.o:
$(CC) -c -I. $(CFLAGS) $(OPTIONS) $<
clean:
rm -f nInvaders $(OFILES)
End result:
root#x86host:~/ninvaders-0.1.1# file nInvaders_IOSXE_MIPS
nInvaders_IOSXE_MIPS: ELF 32-bit MSB executable, MIPS,
MIPS32 rel2 version 1, statically linked, for GNU/Linux 2.6.16, not stripped
Screenshots:
http://imgur.com/a/kf8cu
https://www.youtube.com/watch?v=-qbmKYQ2jCA

makefile error ----> make: *** No rule to make target `mysql.h'

This might sound like a dumb question. But here goes..... I am using a C program called db_access.c which interacts with MySQL (in Ubuntu 10.10 with MySQL Server version: 5.1.49-1ubuntu8.1 (Ubuntu)). Inside the program, I have: include "mysql.h"
When I do the following, everything works out right:
gcc -I/usr/include/mysql db_access.c -lmysqlclient -o db_access
./db_access
Problem arises when I try to integrate it into an existing (and working makefile). The contents of the makefile:
all: MappingServer
#Macro definitions
CC = gcc
CFLAGS = -lm
INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient
MappingServer.o: MappingServer.c map_registration.h
$(CC) $(CFLAGS) -c MappingServer.c
route_aggregation.o: route_aggregation.c map_registration.h
$(CC) $(CFLAGS) -c route_aggregation.c
db_access.o: db_access.c map_registration.h mysql.h
$(CC) $(CFLAGS) $(INCLUDES) -c db_access.c
MappingServer: MappingServer.o route_aggregation.o db_access.o
$(CC) $(LIBS) -o MappingServer MappingServer.o route_aggregation.o db_access.o
clean:
-rm MappingServer.o route_aggregation.o db_access.o
I have two other C programs, MappingServer.c and route_aggregation.c. These 3 files need to be compiled together. By the way, I also did:
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
and
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
So I think the paths are OK. When I do: make all
I get:
root#ahuq-kitchen:/home/ahuq/MappingServer# make all
gcc -lm -c MappingServer.c
gcc -lm -c route_aggregation.c
route_aggregation.c: In function ‘vtysh_input’:
route_aggregation.c:602: warning: function returns address of local variable
make: *** No rule to make target `mysql.h', needed by `db_access.o'. Stop.
Why is this happening?
the line
db_access.o: db_access.c map_registration.h mysql.h
tells make that db_access.o depends on db_access.c, map_registration.h and mysql.h. make complains because mysql.h cannot be found in the current directory (it's in /usr/include/mysql).
see the question Makefile updated library dependency for how to specify libraries as dependencies in make
You put "mysql.h" as a dependency, but it's not in the current directory, so Make thinks it needs to build it, but doesn't know how.
try to remove all the lines like:
MappingServer.o: MappingServer.c map_registration.h
if the map_registration.h is included in the c file, make is smart enough to find it. The only thing to be noticed may be to set the search file path using: -I.

How do I build a PPAPI plugin on Linux?

How do I build a PPAPI plugin for Chromium on Linux?
For example, I want to build the stub example provided by the project. http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/examples/stub/stub.cc?view=markup
So far I have the following Makefile
libexample.so.1.0.1:example.o
g++ -shared -Wl,-soname,libexample.so.1 -o libexample.so.1.0.1 example.o -lc -lppapi_cpp -lppapi_cpp_objects -L /home/carlos/Desktop/ppapi/example/
example.o:
g++ -fPIC -Wall -g -c stub.cc -o example.o -I /home/carlos/Desktop/
clean:
rm example.o libexample.so.1.0.1
run:
google-chrome -d --register-pepper-plugins="/home/carlos/Desktop/ppapi/examples/stub/libexample.so.1.0.1;application/x-ppapi-example"
However, libexample.so.1.0.1 is missing symbols.
nm libexample.so.1.0.1 --demangle -u | grep pp::
Gives me this:
U pp::Module::Get()
U typeinfo for pp::Module
U typeinfo for pp::Instance
Where are those symbols?
I found out that
make -n
allows one to reproduce what a complicated Makefile is doing. From there, it was a matter of some trial and error. Below is the Makefile that works for me.
libppapi_example.so:stub.o
g++ -shared -pthread -Wl,-z,noexecstack -Wl,-soname=libppapi_example.so -o libppapi_example.so -Wl,--start-group stub.o libppapi_cpp.a libppapi_cpp_objects.a -Wl,--end-group
stub.o:
g++ '-DNO_HEAPCHECKER' '-DCHROMIUM_BUILD' '-DENABLE_REMOTING=1' '-DENABLE_GPU=1' '-D__STDC_FORMAT_MACROS' '-DDYNAMIC_ANNOTATIONS_ENABLED=1' '-D_DEBUG' -I/home/carlos/Desktop/chromium/src/ -Werror -pthread -fno-exceptions -Wall -Wno-unused-parameter -Wno-missing-field-initializers -D_FILE_OFFSET_BITS=64 -fvisibility=hidden -pipe -fPIC -fno-strict-aliasing -fPIC -fvisibility=hidden -fvisibility=hidden -O0 -g -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -MMD -MF stub.o.d.raw -c -o stub.o stub.cc
clean:
rm -f stub.o.d.raw stub.o libppapi_example.so
run:
google-chrome -d --register-pepper-plugins="/home/carlos/Desktop/ppapi/examples/stub/libppapi_example.so;application/x-ppapi-example"