Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a C project which spits out an executable. I want to convert that project into a library which I want to use in my QT C++ application.
I am hitting a wall. Can someone provide me any information on it?
So I have been looking at https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_static_library
I created a no-qt project to compile and it generates a .a file.
Here is my .pro file
TEMPLATE = lib
CONFIG += staticlib
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
libmnl/dhcp/dhcpclient.c \
libmnl/dhcp/dhcpmsg.c \
libmnl/dhcp/packet.c \
libmnl/attr.c \
libmnl/callback.c \
libmnl/ifutils.c \
libmnl/nlmsg.c \
libmnl/socket.c \
atc.c \
atchannel.c \
at_tok.c \
device.c \
GobiNetCM.c \
mbim-cm.c \
MPQMUX.c \
qmap_bridge_mode.c \
QMIThread.c \
QmiWwanCM.c \
udhcpc_netlink.c \
util.c
HEADERS += \
libmnl/dhcp/dhcp.h \
libmnl/dhcp/dhcpmsg.h \
libmnl/dhcp/packet.h \
libmnl/ifutils.h \
libmnl/libmnl.h \
atchannel.h \
at_tok.h \
MPQMUX.h \
QMIThread.h \
util.h
DISTFILES +=
QMAKE_CFLAGS += -Wall #-s
QMAKE_LFLAGS += -lpthread -ldl -lrt
LIBS += -pthread
My understanding tells me that my C project spits out an executable instead I want it to spit out a library and a header
Which I could then add it to my QT project
Does this help:
https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
Note that I have C++ libraries that I include in my Qt projects and don't have to do anything special at all. I just produce libFOO.a and then edit my Qt projects .pro file to add -L and -lFOO. Here is a cut & paste from one such project.
LIBS += -L../MyLib/lib -lMyLib
You might also have to add something like this:
INCLUDEPATH += ../MyLib/src
Notice there's no -I on this.
Related
I am trying to link with static C API version of the TensorFlow library.
I built the static library using the following commands:
// get the sources
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
// create a build directory
mkdir builddir
cd builddir
// build the lib using CMake
cmake -S ../tensorflow_src/tensorflow/lite/c -DTFLITE_C_BUILD_SHARED_LIBS:BOOL=OFF
cmake --build . -j
This builds the libtensorflow-lite.a. However, the libtensorflow-lite.a is not self-contained and has its own set of 10 dependencies, stated here in the CMake file:
# TensorFlow Lite dependencies.
find_package(absl REQUIRED)
find_package(eigen REQUIRED)
find_package(farmhash REQUIRED)
find_package(fft2d REQUIRED)
find_package(flatbuffers REQUIRED)
find_package(gemmlowp REQUIRED)
find_package(neon2sse REQUIRED)
find_package(clog REQUIRED)
find_package(cpuinfo REQUIRED) #CPUINFO is used by XNNPACK and RUY library
find_package(ruy REQUIRED)
The question is, how do I find out the .a names of the required sub-libraries?
I used find ./builddir -type f -name "*.a" to list the libraries built by CMake, and expected roughly 10 libs, but the actual list is too long:
./_deps/xnnpack-build/libXNNPACK.a
./_deps/ruy-build/ruy/libruy_pack_avx2_fma.a
./_deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a
./_deps/ruy-build/ruy/libruy_block_map.a
./_deps/ruy-build/ruy/libruy_system_aligned_alloc.a
./_deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a
./_deps/ruy-build/ruy/profiler/libruy_profiler_instrumentation.a
./_deps/ruy-build/ruy/libruy_trmul.a
./_deps/ruy-build/ruy/libruy_cpuinfo.a
./_deps/ruy-build/ruy/libruy_blocking_counter.a
./_deps/ruy-build/ruy/libruy_pack_arm.a
./_deps/ruy-build/ruy/libruy_apply_multiplier.a
./_deps/ruy-build/ruy/libruy_kernel_avx2_fma.a
./_deps/ruy-build/ruy/libruy_prepacked_cache.a
./_deps/ruy-build/ruy/libruy_tune.a
./_deps/ruy-build/ruy/libruy_context_get_ctx.a
./_deps/ruy-build/ruy/libruy_have_built_path_for_avx.a
./_deps/ruy-build/ruy/libruy_ctx.a
./_deps/ruy-build/ruy/libruy_wait.a
./_deps/ruy-build/ruy/libruy_allocator.a
./_deps/ruy-build/ruy/libruy_context.a
./_deps/ruy-build/ruy/libruy_kernel_avx.a
./_deps/ruy-build/ruy/libruy_prepare_packed_matrices.a
./_deps/ruy-build/ruy/libruy_pack_avx512.a
./_deps/ruy-build/ruy/libruy_kernel_arm.a
./_deps/ruy-build/ruy/libruy_denormal.a
./_deps/ruy-build/ruy/libruy_kernel_avx512.a
./_deps/ruy-build/ruy/libruy_frontend.a
./_deps/ruy-build/ruy/libruy_pack_avx.a
./_deps/ruy-build/ruy/libruy_thread_pool.a
./_deps/flatbuffers-build/libflatbuffers.a
./_deps/fft2d-build/libfft2d_fftsg2d.a
./_deps/fft2d-build/libfft2d_fftsg.a
./_deps/farmhash-build/libfarmhash.a
./_deps/clog-build/libclog.a
./_deps/abseil-cpp-build/absl/synchronization/libabsl_graphcycles_internal.a
./_deps/abseil-cpp-build/absl/synchronization/libabsl_synchronization.a
./_deps/abseil-cpp-build/absl/strings/libabsl_strings.a
./_deps/abseil-cpp-build/absl/strings/libabsl_str_format_internal.a
./_deps/abseil-cpp-build/absl/strings/libabsl_cord.a
./_deps/abseil-cpp-build/absl/strings/libabsl_strings_internal.a
./_deps/abseil-cpp-build/absl/status/libabsl_status.a
./_deps/abseil-cpp-build/absl/hash/libabsl_city.a
./_deps/abseil-cpp-build/absl/hash/libabsl_wyhash.a
./_deps/abseil-cpp-build/absl/hash/libabsl_hash.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_reflection.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_program_name.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_internal.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_private_handle_accessor.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_marshalling.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag_internal.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_commandlineflag.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags_config.a
./_deps/abseil-cpp-build/absl/flags/libabsl_flags.a
./_deps/abseil-cpp-build/absl/numeric/libabsl_int128.a
./_deps/abseil-cpp-build/absl/debugging/libabsl_symbolize.a
./_deps/abseil-cpp-build/absl/debugging/libabsl_debugging_internal.a
./_deps/abseil-cpp-build/absl/debugging/libabsl_demangle_internal.a
./_deps/abseil-cpp-build/absl/debugging/libabsl_stacktrace.a
./_deps/abseil-cpp-build/absl/base/libabsl_spinlock_wait.a
./_deps/abseil-cpp-build/absl/base/libabsl_raw_logging_internal.a
./_deps/abseil-cpp-build/absl/base/libabsl_malloc_internal.a
./_deps/abseil-cpp-build/absl/base/libabsl_throw_delegate.a
./_deps/abseil-cpp-build/absl/base/libabsl_exponential_biased.a
./_deps/abseil-cpp-build/absl/base/libabsl_base.a
./_deps/abseil-cpp-build/absl/base/libabsl_log_severity.a
./_deps/abseil-cpp-build/absl/time/libabsl_time_zone.a
./_deps/abseil-cpp-build/absl/time/libabsl_civil_time.a
./_deps/abseil-cpp-build/absl/time/libabsl_time.a
./_deps/abseil-cpp-build/absl/container/libabsl_hashtablez_sampler.a
./_deps/abseil-cpp-build/absl/container/libabsl_raw_hash_set.a
./_deps/abseil-cpp-build/absl/types/libabsl_bad_variant_access.a
./_deps/abseil-cpp-build/absl/types/libabsl_bad_optional_access.a
./_deps/cpuinfo-build/libcpuinfo.a
The state of the libs seems to be the following:
absl: 30 libraries found
eigen: OK, template library defined in the headers
farmhash: OK, 1 library found
fft2d: OK, 2 libraries found
flatbuffers: OK, 1 library found
gemmlowp: OK, headers only
neon2sse: OK, headers only
clog: OK, 1 library found
cpuinfo: OK, 1 library found
ruy: 30 libraries found
All in all, most libs are OK, either there is 1 lib to link with, or the libs are header-only. What remains to be the problem are:
absl
ruy
because they contain about 30 .a libs.
Not sure if I have to link with all of those? It would be very cumbersome, as my build system is Meson and I am using custom_target() to link with TensorFlow.
A year later, but I just went through this myself, so here goes my answer.
Based on my experience (using a makefile and without your -DTFLITE_C_BUILD_SHARED_LIBS:BOOL=OFF) a program that performs inference does not need to link to Abseil.
You need to link to all other libs you mentioned, except ruy_kernel_arm and ruy_pack_arm, assuming you're running your program on the x64 platform. (Annoyingly -DTFLITE_ENABLE_RUY=OFF is not respected when building TfLite, so you're stuck with Ruy)
Detailed steps:
Build TfLite:
mkdir ~/my_tflite_project
cd ~/my_tflite_project/
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
mkdir tflite_build_x64
cd tflite_build_x64/
cmake ../tensorflow_src/tensorflow/lite/
/* You may encounter two CMake messages:
-- The Fortran compiler identification is unknown
I believe a Fortran compiler is only necessary to build Fortran bindings for TfLite.
-- Could NOT find CLANG_FORMAT: Found unsuitable version "0.0", but required is exact version "9" (found CLANG_FORMAT_EXECUTABLE-NOTFOUND)
sudo apt install clang-format-9
Annoyingly you need clang-format-9, plain clang-format (version 13, the newest) won't do. */
cmake --build . -j 4
Relevant libs:
$ cd ~/my_tflite_project/tflite_build_x64
$ ls *.a
libtensorflow-lite.a
$ ls pthreadpool/*.a
pthreadpool/libpthreadpool.a
$ ls _deps/*/*.a
_deps/clog-build/libclog.a _deps/farmhash-build/libfarmhash.a _deps/fft2d-build/libfft2d_fftsg2d.a _deps/xnnpack-build/libXNNPACK.a
_deps/cpuinfo-build/libcpuinfo.a _deps/fft2d-build/libfft2d_fftsg.a _deps/flatbuffers-build/libflatbuffers.a
$ ls _deps/ruy-build/ruy/*.a
_deps/ruy-build/ruy/libruy_allocator.a _deps/ruy-build/ruy/libruy_ctx.a _deps/ruy-build/ruy/libruy_kernel_avx.a _deps/ruy-build/ruy/libruy_prepacked_cache.a
_deps/ruy-build/ruy/libruy_apply_multiplier.a _deps/ruy-build/ruy/libruy_denormal.a _deps/ruy-build/ruy/libruy_kernel_avx2_fma.a _deps/ruy-build/ruy/libruy_prepare_packed_matrices.a
_deps/ruy-build/ruy/libruy_block_map.a _deps/ruy-build/ruy/libruy_frontend.a _deps/ruy-build/ruy/libruy_kernel_avx512.a _deps/ruy-build/ruy/libruy_system_aligned_alloc.a
_deps/ruy-build/ruy/libruy_blocking_counter.a _deps/ruy-build/ruy/libruy_have_built_path_for_avx.a _deps/ruy-build/ruy/libruy_pack_arm.a _deps/ruy-build/ruy/libruy_thread_pool.a
_deps/ruy-build/ruy/libruy_context.a _deps/ruy-build/ruy/libruy_have_built_path_for_avx2_fma.a _deps/ruy-build/ruy/libruy_pack_avx.a _deps/ruy-build/ruy/libruy_trmul.a
_deps/ruy-build/ruy/libruy_context_get_ctx.a _deps/ruy-build/ruy/libruy_have_built_path_for_avx512.a _deps/ruy-build/ruy/libruy_pack_avx2_fma.a _deps/ruy-build/ruy/libruy_tune.a
_deps/ruy-build/ruy/libruy_cpuinfo.a _deps/ruy-build/ruy/libruy_kernel_arm.a _deps/ruy-build/ruy/libruy_pack_avx512.a _deps/ruy-build/ruy/libruy_wait.a
Construct MWE using TfLite:
$ cd ~/my_tflite_project
$ mkdir my_dev_x64
$ cd my_dev_x64/
/* Construct minimal.cpp and makefile below */
$ cat minimal.cpp
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include <iostream>
int main() {
std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile("your_network_here.tflite");
tflite::ops::builtin::BuiltinOpResolver resolver;
std::cout "Done\n";
return EXIT_SUCCESS;
}
$ cat makefile
COMPILER := g++
LINKER := g++
CXX_FILES := minimal.cpp
OBJ_FILES := $(CXX_FILES:.cpp=.o)
EXE_FILE := app
INCLUDE_DIRS := -I../tensorflow_src -I../tflite_build_x64/flatbuffers/include
LIB_DIRS := \
-L../tflite_build_x64 \
-L../tflite_build_x64/_deps/fft2d-build \
-L../tflite_build_x64/_deps/flatbuffers-build \
-L../tflite_build_x64/_deps/ruy-build/ruy \
-L../tflite_build_x64/_deps/farmhash-build \
-L../tflite_build_x64/_deps/xnnpack-build \
-L../tflite_build_x64/_deps/cpuinfo-build \
-L../tflite_build_x64/_deps/clog-build \
-L../tflite_build_x64/pthreadpool
LIBS := \
-ltensorflow-lite \
-lfft2d_fftsg \
-lfft2d_fftsg2d \
-lflatbuffers \
-lruy_ctx \
-lruy_allocator \
-lruy_frontend \
-lruy_context_get_ctx \
-lruy_context \
-lruy_apply_multiplier \
-lruy_prepacked_cache \
-lruy_tune \
-lruy_cpuinfo \
-lruy_system_aligned_alloc \
-lruy_prepare_packed_matrices \
-lruy_trmul \
-lruy_block_map \
-lruy_denormal \
-lruy_thread_pool \
-lruy_blocking_counter \
-lruy_wait \
-lruy_kernel_avx \
-lruy_kernel_avx2_fma \
-lruy_kernel_avx512 \
-lruy_pack_avx \
-lruy_pack_avx2_fma \
-lruy_pack_avx512 \
-lruy_have_built_path_for_avx \
-lruy_have_built_path_for_avx2_fma \
-lruy_have_built_path_for_avx512 \
-lfarmhash \
-lXNNPACK \
-lpthreadpool \
-lcpuinfo \
-lclog
CXX_FLAGS := -Wall #-pedantic
LINK_FLAGS :=
#Do not print the output of the commands
.SILENT:
#Phony targets do not represent actual files, so files with the following names are ignored
.PHONY: clean depend
#Link object files to form an executable file
$(EXE_FILE): $(OBJ_FILES)
$(LINKER) $(LINK_FLAGS) $(OBJ_FILES) -o $(EXE_FILE) $(LIB_DIRS) $(LIBS)
#Compile cpp files to object files
%.o: %.cpp
$(COMPILER) $(CXX_FLAGS) $(INCLUDE_DIRS) -c $<
#Remove object files, executable, and possible linkinfo files
clean:
-rm -f $(OBJ_FILES) $(EXE_FILE)
#Generate dependency file
depend:
$(COMPILER) $(CXX_FLAGS) $(INCLUDE_DIRS) -MM $(CXX_FILES) > make.dep
#Include dependency file
-include make.dep
Build and run MWE:
$ cd ~/my_tflite_project/my_dev_x64
$ make
$ ./app
Done
Hopefully that helps you or some other poor fellow to get TfLite C++ working.
When trying to compile my code, I get a linker error:
undefined reference to ‘xdg_popup_interface’
It seems to occur when trying to build wlr-layer-shell-v1-client-protocol.o, I think, or something like that, I’ll have to look at the output tomorrow.
AFAIK xdg_popup should be defined by wayland-protocols? My configure.ac.in has this line:
PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.13], [ac_wayland_protocols_pkgdatadir=`$PKG_CONFIG --variable=pkgdatadir wayland-protocols`])
and my src/Makefile.am has this:
xfway_CFLAGS = \
$(WAYLAND_SERVER_CFLAGS) \
$(WAYLAND_PROTOCOLS_CFLAGS) \
$(LIBWESTON_CFLAGS) \
$(LIBWESTON_DESKTOP_CFLAGS) \
$(LIBINPUT_CFLAGS) \
$(XKBCOMMON_CFLAGS) \
$(EGL_CFLAGS) \
$(EVDEV_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBXFCONF_CFLAGS)
xfway_LDADD = \
$(WAYLAND_SERVER_LIBS) \
$(WAYLAND_PROTOCOLS_LIBS) \
$(LIBWESTON_LIBS) \
$(LIBWESTON_DESKTOP_LIBS) \
$(LIBINPUT_LIBS) \
$(XKBCOMMON_LIBS) \
$(EGL_LIBS) \
$(EVDEV_LIBS) \
$(PIXMAN_LIBS) \
$(GTK_LIBS) \
$(LIBXFCONF_LIBS)
The autotools output listed no cflags or libs for wayland-protocols, is this normal? Though autotools detected an installed version, so it’s definitely installed.
Here is the rest of my code:
https://github.com/adlocode/xfway
This seems to be a part that mentions xdg-popup:
https://github.com/adlocode/xfway/blob/master/protocol/wlr-layer-shell-unstable-v1.xml#L194
As far as I can see everything that is needed is there, what am I missing?
Update:
Is it that I have to generate xdg-shell header files myself using wayland-scanner?
I solved this by generating header files from the xdg-shell XML file using wayland-scanner, and compiling them into my project.
I planned on adding sound effects to a smal project.
i downloaded the SDL_Mixer dev-library for mingw32,
moved all the files from its lib folder to the mingw32 lib folder, did the same for include and bin.
But iam still not able to compile anything using #include SDL2/SDL_mixer.h.
´C:/Development/SDL Mixer/include/SDL2/SDL_mixer.h:25:10: fatal error: SDL_stdinc.h: No such file or directory´
Maybe it is my makefile.
´build:
gcc -Wfatal-errors \
-std=c99 \
./*.c \
-I"C:\Development\SDL2 MinGW 64\include" \
-L"C:\Development\SDL2 MinGW 64\lib" \
-I"C:\Development\SDL Mixer\include" \
-L"C:\Development\SDL Mixer\lib" \
-lmingw32 \
-lSDL2main \
-lSDL2 \
-o example.exe´
i dont know why files are missing.
I can't setup Qt Creator for GTK+ on Ubuntu. I'm trying to compile this example but I got errors complaining about header files :
but I fixed them by adding this to the .pro file
INCLUDEPATH += /usr/include/gtk-2.0 \
/usr/include/glib-2.0 \
/usr/lib/i386-linux-gnu/glib-2.0/include/ \
/usr/include/cairo/ \
/usr/include/pango-1.0/ \
/usr/lib/i386-linux-gnu/gtk-2.0/include/ \
/usr/include/gdk-pixbuf-2.0/ \
/usr/include/atk-1.0/
but I don't know what to add for the LIBS +=
It worked by adding
unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gtk+-2.0
I have compiled Ffmpeg (1.0) with newt configuration:
./configure --disable-doc --disable-ffplay --disable-ffprobe --disable-ffserver --disable-avdevice --disable-avfilter --disable-pthreads --disable-everything --enable-muxer=flv --enable-encoder=flv --enable-encoder=h263 --disable-mmx --disable-shared --prefix=bin/ --disable-protocols --disable-network --disable-debug --disable-asm --disable-stripping
It compiled - no errors - headers and libs (static .a) are in place. (special experimental cigwin, experimental gcc, with no asm options, and no known by ffmpeg platform defines) (yet I have compiled and tested boost on it)
Now I try to compile my app. I get next exceptions:
../ffmpeg-1.0/bin/lib/libavcodec.a: error: undefined reference to 'exp'
../ffmpeg-1.0/bin/lib/libavcodec.a: error: undefined reference to 'log'
My compiler build line looks like this:
g++ -static -emit-swf -o CloudClient.swf -I../boost/boost_libraries/install-dir/include -I../ffmpeg-1.0/bin/include -L../boost/boost_libraries/install-dir/lib -L../ffmpeg-1.0/bin/lib \
timer.o \
audio_encoder.o \
audio_generator.o \
video_encoder.o \
video_generator_rainbow.o \
simple_synchronizer.o \
multiplexer.o \
transmitter.o \
graph_runner.o \
cloud_client.o \
-pthread \
-lswscale \
-lavutil \
-lavformat \
-lavcodec \
-lboost_system \
-lboost_date_time \
-lboost_thread
So as you see quite complex and I already have all object files compiled and ready... Only one thing left - link it all to ffmpeg (striped from ffmpeg version compiled with boost)
Tried adding -lm - no help...
Well here my question is - how to get list of libraries ffmpeg linked to (like -lm etc)?
If in Linux, try
ldd /path/to/ffmpeg-binary
or
ldd `which ffmpeg`