question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Compile "Embed" Demo

See original GitHub issue

I was looking for a way to create executable from cython, and I found the demo at (https://github.com/cython/cython/tree/master/Demos/embed).

I downloaded the repo as I already had Cython Installed, I ran the command make on terminal but it failed with the following terminal message.

palash@ash:~/Downloads/cython-master/Demos/embed$ make
gcc -pthread -B /home/palash/anaconda3/compiler_compat -Wl,--sysroot=/ -c embedded.c -I/home/palash/anaconda3/include/python3.6m -I/home/palash/anaconda3/include/python3.6m
gcc -pthread -B /home/palash/anaconda3/compiler_compat -Wl,--sysroot/ -o embedded embedded.o -L/home/palash/anaconda3/lib -L/home/palash/anaconda3/lib/python3.6/config-3.6m-i386-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic
/home/palash/anaconda3/compiler_compat/ld: unrecognized option '--sysroot/'
/home/palash/anaconda3/compiler_compat/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Makefile:19: recipe for target 'embedded' failed
make: *** [embedded] Error 1

MY OS : Ubuntu 17.04 32bit GCC :

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7-20170407-0ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=i686-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 7.0.1 20170407 (experimental) [trunk revision 246759] (Ubuntu 7-20170407-0ubuntu2) 

PYTHON : 3.6 Anaconda Distribution

Anyone With Help?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
scodercommented, Jul 8, 2018

You can set an rpath using -Wl,-rpath=....

See (and search for rpath in) https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html

1reaction
bauripalashcommented, May 3, 2018

I think I solved the problem. Here’s my new makefile, I tweaked the LINKCC a little to make it work

# Makefile for creating our standalone Cython program
PYTHON := python
PYVERSION := $(shell $(PYTHON) -c "import sys; print(sys.version[:3])")
PYPREFIX := $(shell $(PYTHON) -c "import sys; print(sys.prefix)")

INCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_python_inc())")
PLATINCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_python_inc(plat_specific=True))")
LIBDIR1 := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
LIBDIR2 := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('LIBPL'))")
PYLIB := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('LIBRARY')[3:-2])")

CC := $(shell $(PYTHON) -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('CC'))")
LINKCC := gcc -pthread -B /home/palash/anaconda3/compiler_compat -Wl,--sysroot=/
LINKFORSHARED := $(shell $(PYTHON) -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('LINKFORSHARED'))")
LIBS := $(shell $(PYTHON) -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('LIBS'))")
SYSLIBS :=  $(shell $(PYTHON) -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SYSLIBS'))")

embedded: embedded.o
	$(LINKCC) -o $@ $^ -L$(LIBDIR1) -L$(LIBDIR2) -l$(PYLIB) $(LIBS) $(SYSLIBS) $(LINKFORSHARED)

embedded.o: embedded.c
	$(CC) -c $^ -I$(INCDIR) -I$(PLATINCDIR)

CYTHON := ../../cython.py
embedded.c: embedded.pyx
	@$(PYTHON) $(CYTHON) --embed embedded.pyx

all: embedded

clean:
	@echo Cleaning Demos/embed
	@rm -f *~ *.o *.so core core.* *.c embedded test.output

test: clean all
	PYTHONHOME=$(PYPREFIX) LD_LIBRARY_PATH=$(LIBDIR1):$$LD_LIBRARY_PATH ./embedded > test.output
	$(PYTHON) assert_equal.py embedded.output test.output

I ran the test make test and it gave me Files identical output

But I Have a Question… If i run ./embedded it gives me this

$ ./embedded
./embedded: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

but if i run this PYTHONHOME=/home/palash/anaconda3 LD_LIBRARY_PATH=/home/palash/anaconda3/lib:$LD_LIBRARY_PATH ./embedded as mentioned in make test it works perfectly.

So My Question Is, can’t I just invoke the command ./embedded and it runs or I have to run the lengthy command (mentioned above) every time to run my program?

and

Is there any way to fix the LINKCC problem permanently so I don’t have to tweak Makefiles every time?

Read more comments on GitHub >

github_iconTop Results From Across the Web

go:embed produces error when "go.mod" has go version ...
Introducing embed dependency in an existing library (module) seems to effectively mean issuing a major version. Because isolating embed in a new ...
Read more >
How to Use //go:embed - The Ethically-Trained Programmer
The basic idea of embedding is that by adding a special comment to your code, Go will know to include a file or...
Read more >
possible inconsistency in the embed package documentation
This implies that any embedded file must be in the module's own file tree. It cannot be in a parent directory above the...
Read more >
embed - Go Packages
Package embed provides access to files embedded in the running Go program. Go source files that import "embed" can use the //go:embed directive...
Read more >
Embedding Python in C, linking fails with undefined reference ...
I am trying to compile the example from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found