I am working on a C++ project and I need to use libtcl.
I am running Ubuntu 12.10 32bits and there is a problem when I try to compile my files :
g++ -o executable executable.o -L/usr/share/tcltk -lncurses -ltcl
/usr/bin/ld: cannot find -ltcl
libncurses is found but not libtcl...
Do you have any idea?
I have seen that libtcl8.4.so.0 libtcl8.5.so.0 exist in /usr/lib
The makefile that I am using looks like this :
CC = g++
CFLAGS = -g
LDFLAGS =
EXEC = executable
LIB = -L/usr/share/tcltk -lncurses -ltcl
all: executable
executable: executable.o
$(CC) $(LDFLAGS) -o $(EXEC) executable.o $(LIB)
executable.o: executable.cpp
$(CC) $(CFLAGS) -c executable.cpp
clean:
rm -f executable executable.o
Thanks
(Answered in a comment. See Question with no answers, but issue solved in the comments (or extended in chat) )
#soon wrote:
just create symlink to the your library like so #ln -s /usr/lib/libtcl8.5.so.0 /usr/lib/libtcl.so
Related
I'm trying to build a python wrapper using the following Makefile:
CC=/usr/local/opt/llvm/bin/clang
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
LAPACKLDFLAGS=/usr/lib64/atlas/libsatlas.so # single-threaded blas
#LAPACKLDFLAGS=/usr/lib64/atlas/libtatlas.so # multi-threaded blas
#BLAS_THREADING=-D MULTITHREADED_BLAS # remove this if wrong
endif
ifeq ($(OS_NAME),Darwin) # Mac OS X
LAPACKLDFLAGS=-framework Accelerate # for OS X
endif
LAPACKCFLAGS=-Dinteger=int $(BLAS_THREADING)
STATICLAPACKLDFLAGS=-fPIC -Wall -g -fopenmp -static -static-libstdc++ /home/lear/douze/tmp/jpeg-6b/libjpeg.a /usr/lib64/libpng.a /usr/lib64/libz.a /usr/lib64/libblas.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libgfortran.a /usr/lib/gcc/x86_64-redhat-linux/4.9.2/libquadmath.a # statically linked version
CFLAGS= -fPIC -Wall -g -std=c++11 $(LAPACKCFLAGS) -fopenmp -DUSE_OPENMP -O3
LDFLAGS=-fPIC -Wall -g -ljpeg -lpng -fopenmp
CPYTHONFLAGS=-I/usr/include/python2.7
SOURCES := $(shell find . -name '*.cpp' ! -name 'deepmatching_matlab.cpp')
OBJ := $(SOURCES:%.cpp=%.o)
HEADERS := $(shell find . -name '*.h')
all: deepmatching
.cpp.o: %.cpp %.h
$(CC) -o $# $(CFLAGS) -c $+
deepmatching: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(LDFLAGS) $(LAPACKLDFLAGS)
deepmatching-static: $(HEADERS) $(OBJ)
$(CC) -o $# $^ $(STATICLAPACKLDFLAGS)
python: $(HEADERS) $(OBJ)
# swig -python $(CPYTHONFLAGS) deepmatching.i # not necessary, only do if you have swig compiler
/usr/local/opt/llvm/bin/clang $(CFLAGS) -c deepmatching_wrap.c $(CPYTHONFLAGS)
/usr/local/opt/llvm/bin/clang -shared $(LDFLAGS) $(LAPACKLDFLAGS) deepmatching_wrap.o $(OBJ) -o _deepmatching.so $(LIBFLAGS)
clean:
rm -f $(OBJ) deepmatching *~ *.pyc .gdb_history deepmatching_wrap.o _deepmatching.so deepmatching.mex???
Previously, CC was set to g++, however, when I tried to build it like this, I'd get "ERROR: clang: error: unsupported option '-fopenmp".
Now I installed "brew install llvm" as this comes with the -fopenmp option. The unsupported error is resolved for now, but now the compiler doesn't seem to find a header file:
(base) MacBook-Pro-van-Brent:deepmatching BrentDeHauwere$ make python
/usr/local/opt/llvm/bin/clang -o hog.o -fPIC -Wall -g -std=c++11 -Dinteger=int -fopenmp -DUSE_OPENMP -O3 -I/usr/local/opt/llvm/include -c hog.cpp
In file included from hog.cpp:18:
In file included from ./std.h:20:
/usr/local/opt/llvm/bin/../include/c++/v1/math.h:300:15: fatal error: 'math.h' file not found
#include_next <math.h>
^~~~~~~~
1 error generated.
make: *** [hog.o] Error 1
I've tried setting options (I might have set them incorrectly) like -L/usr/local/opt/llvm/lib and -I/usr/local/opt/llvm/include, but no result so far. Any idea how I could point the compiler to the right direction for the header files?
Try running xcode-select —install in your terminal. This installs the xcode command line tools which should also install system headers files (as part of the macos sdk) and set your system include paths.
I am trying to cross compile my hello world app on C from Ubuntu linux for Windows platform. So, to compile the app I am using this Makefile:
CC = g++
IDIR = -Iinclude
SRC = src
CFLAGS = -Wall -Wextra
LFLAGS = -mwindows
main.out: main.o
$(CC) $(CFLAGS) $(IDIR) $(LFLAGS) $^ -o $#
main.o: $(SRC)/main.c
$(CC) $(CFLAGS) $(IDIR) -c -o $# $^
As the result of cmmand make -f windows.mk I have such error:
g++: error: unrecognized command line option ‘-mwindows’
I have already tried gcc and g++. Is there way to compile it without making my own crosscompiler?
To cross compile for windows you would need mingw-w64 or use i686-w64-mingw32-g++
sudo apt-get install mingw-w64 For more info :
https://arrayfire.com/cross-compile-to-windows-from-linux/
Thanks a lot #HolyBlackCat
I've tried to using x86_64-w64-mingw32-g++ instead of just g++ or gcc without -mwindows and it succeed.
So I am trying to compile a c++ program and have the executable be 32-bit instead of 64-bit. The system (using a program to simulate a system) I want to run it on is 32-bit and seeing as compiling the program yields 64-bit ELF files I cannot run them. I have added the -m32 flag to the makefile and when compiling i get the following errors:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
when using sudo apt install -lstdc++ it simply says it cannot find the library. Anybody perhaps able to give me some direction? I am running all of this using remote wsl in visual studio code on a windows 10 machine. Ultimately I just want the compiled executables from this program to be 32-bit ELFs instead of 64-bit.
This is the make file The program im trying to compile is a benchmark suite located here https://github.com/alifahmed/hopscotch. This is the makefile otherwise located in /cpu/2_bandwidth:
TARGET = bandwidth
.PHONY: all clean $(TARGET)
# directories
INC_DIR = ../include
KERN_DIR = ../kernels
CMN_DIR = ../common
OBJ_DIR = obj
# compiler flags ADDED -m32 FLAG
CXX = g++
CXXFLAGS = -m32 -O3 -fopenmp -march=native -I$(INC_DIR) -std=c++14 $(USER_DEFS)
# header files
HEADERS = $(wildcard $(INC_DIR)/*.h)
# src files
SRC = $(wildcard *.cpp) $(wildcard $(KERN_DIR)/*.cpp) $(wildcard $(CMN_DIR)/*.cpp)
# object files
OBJ = $(SRC:.cpp=.o)
all: $(TARGET)
clean:
#rm -rf $(OBJ)
#rm -rf $(TARGET)
#echo "Cleaned..."
%.o: %.cpp $(HEADERS)
$(CXX) $(CXXFLAGS) -c -o $# $<
$(TARGET): $(OBJ)
$(CXX) $(CXXFLAGS) $^ -o $#```
That's easy, just install the 32-bit development libraries
$ sudo apt update
$ sudo apt install gcc-multilib g++-multilib
I'm trying to compile tensorflow c_api using Makefile. I need help to add the tensorflow libraries in the makefile. I'm running it on Ubuntu.
Here I have attached the folder structure of the project,
folder structure
I have also added the Makefile below.
CC = g++
CFLAGS = -c -Wall
INCLUDES = -I "tensorflow/c"
LIBS =-L "lib" -ltensorflow -ltensorflow_framework
all : exec
exec : simple.o
$(CC) -o exec simple.o $(INCLUDES) $(LIBS)
.cpp.o:
$(CC) $(CFLAGS) $<
clean:
rm -rf *.
The program compiles without error,
g++ -c -Wall simple.cpp
g++ -o exec simple.o -I "tensorflow/c" -L "lib" -ltensorflow -ltensorflow_framework
but when i run the exec I get the following error,
./exec: error while loading shared libraries: libtensorflow.so.1: cannot open shared object file: No such file or directory
You have to make sure that lib is on LD_LIBRARY_PATH.
export LD_LIBRARY_PATH=`pwd`/lib:${LD_LIBRARY_PATH}
./exec
In Python 3, I am trying to import a shared library compiled in C++. Currently, I have these packages installed on CentOS 7:
g++ --version -> g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
conda list anaconda$ -> Anaconda 3 version 5.2.0 with build channel py36_3
A simple file in C++ greet.cpp is compiled into a shared library greet.so with Boost.Python. I followed a video on youtube Simple Demo of Boost Python of Python calling C++ library but it failed to find Python.h for some reasons. I had to changed a few things in makefile and eventually I compiled all with no errors. However, when I try to import the shared library pygreet.so in Python interpreter as a module: import pygreet, I get this error:
ImportError: /home/.../cpp/code/pygreet.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
I tried to see what this thing is: nm pygreet.so | less -p "_ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE" and found these line:
0000000000008916 W _ZN5boost6python3da simpleefIPFSsvEEEvPKcT_
U _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
I am rather a beginner at using shared libraries and I really don't know how to proceed. Below, I am showing the files in case someone can see I missed something important.
Thanks.
greet.cpp:
#include <string>
#include <boost/python.hpp>
namespace py = boost::python;
std::string greet() {
return "hello, world";
}
int square(int number) {
return number * number;
}
BOOST_PYTHON_MODULE(pygreet)
{
// Add regular functions to the module.
py::def("greet", greet);
py::def("square", square);
}
makefile:
CXX = g++
PYLIBPATH = $(shell python3-config --exec-prefix)/lib
LDFLAGS = -L$(PYLIBPATH)
LFLAGS = $(shell python3-config --libs) -lboost_python
CFLAGS = -Wall -Werror
INCLUDES = $(shell python3-config --includes)
SOURCE = greet.cpp
TARGET = pygreet.so
OBJ = $(SOURCE:.cpp=.o)
default: $(TARGET)
#echo $(TARGET) compiled!
$(TARGET): $(OBJ)
$(CXX) $(CFLAGS) $(LDFLAGS) $(LFLAGS) -Wl,-rpath,$(PYLIBPATH) -shared $< -o $#
greet.o: $(SOURCE)
$(CXX) $(CFLAGS) $(INCLUDES) -fpic -c $< -o $#
clean:
rm -rf *.so *.o
.PHONY: deafult clean
Edit.
As suggested in comment, I changed the line in makefile:
PYLIBPATH = $(shell python3-config --exec-prefix)/lib
LDFLAGS = -L$(PYLIBPATH)
LFLAGS = $(shell python3-config --libs) -lboost_python
to
PYLIBPATH = $(shell python3-config --exec-prefix)
LDFLAGS = $(shell python3-config --ldflags) -lboost_python
and then
$(CXX) $(CFLAGS) $(LDFLAGS) $(LFLAGS) -Wl,-rpath,$(PYLIBPATH) -shared $< -o $#
to
$(CXX) $(CFLAGS) $(LDFLAGS) -Wl,-rpath,$(LDFLAGS) -shared $< -o $#
but still have the same error.
Boost provides separate libraries for Python 2 and Python 3. If you are using Python 3, you need to link with the Python 3 specific library, otherwise you will get undefined symbol errors at module loading time.
On Ubuntu, the library may be called libboost_python-py35.so. I'm pretty sure (but didn't verify) that different minor versions of the boost.python library are upwards compatible, so you may use libboost_python-py35.so with Python 3.6.
If such library is not present on your system, chances are your distro doesn't ship it, in which case you need to build boost.python from sources.