How to recompile an existing linux application - linux

I am looking to edit and recompile the hcitool.c of bluez version 5.31. I installed the bluez 5.31 by following the procedure from the answer of this:
Bluetooth Low Energy in C - using Bluez to create a GATT server
In my trial, I duplicated the hcitool.c file and named it as myhcitool.c inside the tools folder and I use the command
gcc -o myhcitool.o myhcitool.c.
This gives me an error
myhcitool.c:43:27: fatal error: lib/bluetooth.h: No such file or directory
#include "lib/bluetooth.h"
^
compilation terminated.
I tried copying the myhcitool.c outside the tools folder and compile it there. That gave me a bunch of errors something like this:
/tmp/ccj1QmZK.o: In function `dev_info':
myhcitool.c:(.text+0x293): undefined reference to `ba2str'
/tmp/ccj1QmZK.o: In function `conn_list':
myhcitool.c:(.text+0x501): undefined reference to `ba2str'
myhcitool.c:(.text+0x50f): undefined reference to `hci_lmtostr'
myhcitool.c:(.text+0x586): undefined reference to `bt_free'
/tmp/ccj1QmZK.o: In function `cmd_dev':
I also tried editing the hcitool.c itself by modifying a simple printf in there and then redo the 'make' and 'make install' commands for the whole bluez. After that, when I tried running the hcitool, the modification that I did has no effect.

The compilation errors clearly state that you are missing files and directories and that there are undefined references to types (since you are missing the files). You are copying a file outside of its directory and trying to compile it. This won't work as the includes (and more) required for it to compile correctly are missing.
If you want to edit hcitool directly you should download the Bluez source, unpack it, cd into it and ./configure it. The makefile will be generated and you can use make to build the executables. If you make change to the hcitool.c file you should make sure you recompile it and are running it inside the directory as ./hcitool and not as general hcitool as this runs the executable installed to your system, rather than the one you edited.
If you want to build it outside of the Bluez directory as a sort of standalone, you will have to copy all the files and folders defined in the #include <x> statements that are needed and make a separate makefile for those, since copying the existing one will probably not work.
If you want to add a new file to the Bluez source, make sure you also make the correct Makefile edits so that it is included during compilation.
I'd like to add that hcitool has not been maintained for a long time and is on its way to being phased out of Bluez, so maybe you should take a different approach altogether!

Related

FreeBSD - how do I compile PolyML including XWindows module

On freebsd 12 the xwindows module in PolyML is not implemented so I am trying to compile its source outside the ports tree. It does compile, but I cannot open the XWindows module in poly.
What I did is:
copied libX11 to /usr/lib to be sure, and made symbolic links in
/usr/include for Xm and X11 to /usr/local/include.
inserted one space in xwindows.cpp because of a clang error
added these options to configure :
--x-includes=/usr/local/include/X11 --x-libraries=/usr/local/lib/ --with-x --with-system-libffi
set the environment : LDFLAGS=-L/usr/local/lib/gcc7 , where libstdc++
is located
tried with clang and gcc7
The code compiles without further errors. There is a file xwindows.o, 375160 bytes for cc and 291184 for gcc7.
The log contains
Created structure XWindows
Created structure Motif
I run poly from where it was compiled, and get
open XWindows
poly: : error: Structure (XWindows) has not been declared Found near open XWindows.
The non-graphics modules open normally
What am i doing wrong here ?? thanks for pointers
I
added CONFIGURE_ENV= LDFLAGS=-L/usr/local/lib to the port's Makefile, and
inserted a space before ZERO_X in xwindows.cpp
after which the ports code compiled, including the 2 modules in poly
My error has been to omit a make rmconfig before new compilation, and I had originally compiled poly without motif, so that kept coming back

binutils make error for readelf

When I run make binutils/readelf I get the following error:
In file included from readelf.c:43:0:
sysdep.h:23:25: fatal error: alloca-conf.h: No such file or directory
#include "alloca-conf.h"
What dependency am I missing? How do I just build and compile readelf without making the rest of binutils?
What has actually happened is that you do not have a Makefile or at least not one defining binutils/readelf target. But since there is a binutils/readelf.c file, make still ran and tried to compile and link binutils/readelf using its implicit pattern rules... and failed because this source file cannot be built without corresponding configuration.
This is just to add a bit more detail. Long story short, run ./configure and make as suggested in the comments and collect your resulting readelf. Much easier then trying to isolate a solitary item build out of autotools based project. You add -I to CFLAGS to find alloca-conf.h, you'll just run into another problem like that.

Linker Issues with boost::thread under linux using Eclipse and CMake

I'm in the process of attempting to port some code across from PC to Ubuntu, and am having some issues due to limited experience developing under linux.
We use CMake to generate all our build stuff. Under windows I'm making VS2010 projects, and under Linux I'm making Eclipse projects. I've managed to get my OpenCV stuff ported across successfully, but am having major headaches trying to port my threaded boost apps.
Just so we're clear, the steps I have followed so-far on a clean Ubuntu 12 installation. (I've done 2 clean re-installs to try and fix potential library cock-ups, now I'm just giving up and asking):
Install Eclipse and Eclipse CDT using my package manager
Install CMake and CMake Gui using my package manager
Install libboost-all-dev using my package manager
So-far that's all I've done. I can create the eclipse project using CMake with no errors, so CMake is successfully finding my boost install. When I try and build through eclipse is when I get issues; The app I'm attempting to build uses boost::asio for some UDP I/O and boost::thread to create worker threads for the asio I/O services. I can successfully compile each module, but when I come to link I get spammed with errors such as:
/usr/bin/c++ CMakeFiles/RE05DevelopmentDemo.dir/main.cpp.o CMakeFiles/RE05DevelopmentDemo.dir/RE05FusionListener/RE05FusionListener.cpp.o CMakeFiles/RE05DevelopmentDemo.dir/NewEye/NewEye.cpp.o -o RE05DevelopmentDemo -rdynamic -Wl,-Bstatic -lboost_system-mt -lboost_date_time-mt -lboost_regex-mt -lboost_thread-mt -Wl,-Bdynamic
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `void boost::call_once<void (*)()>(boost::once_flag&, void (*)()) [clone .constprop.98]':
make[2]: Leaving directory `/home/david/Code/Build/Support/RE05DevDemo'
(.text+0xc8): undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::interruption_enabled()':
(.text+0x540): undefined reference to `pthread_getspecific'
make[1]: Leaving directory `/home/david/Code/Build/Support/RE05DevDemo'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()':
(.text+0x570): undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()':
(.text+0x59f): undefined reference to `pthread_getspecific'
Some Gotchas that I have collected from other StackOverflow posts and have already checked:
The boost libs are all present at /usr/lib
I am not getting any compile errors for inability to find the boost headers, so they must be getting found.
I am trying to link statically, but I believe eclipse should be passing the correct arguments to make that happen since my CMakeLists.txt includes SET(Boost_USE_STATIC_LIBS ON)
I'm officially out of ideas here, I have tried doing local builds of boost and a bunch of other stuff with no more success. I even re-installed Ubuntu to ensure I haven't completely fracked the libs directories and links with multiple weird versions or anything else. Any help would be muchly appreciated.
Correct mechanism is to use Threads package:
find_package(Threads)
#...
target_link_libraries(my_app ${CMAKE_THREAD_LIBS_INIT} ...)
See also cmake and libpthread
When you are building your targets, add -lpthread and it will compile.
See this other thread.
OK, so I found the solution.
It was to do with the absence of the -lpthread flag in the link command. In order to get CMake to link appropriately, then the TARGET_LINK_LIBRARIES line needs to be edited. My edit is:
Original:
TARGET_LINK_LIBRARIES( RE05DevelopmentDemo ${Boost_LIBRARIES} )
Modified and working:
IF(WIN32)
TARGET_LINK_LIBRARIES( RE05DevelopmentDemo ${Boost_LIBRARIES} )
ELSE(WIN32)
TARGET_LINK_LIBRARIES( RE05DevelopmentDemo ${Boost_LIBRARIES} pthread )
ENDIF(WIN32)
I'm guessing that I should probably change the ELSE(WIN32) to an elseif for or use the CMake command FindThreads to link in pthread if needed, but I'm not sure how to do that at the moment and have more imporatant things on my plate given the time I've lost. Interestingly enough, I noticed my link command now has two -lpthread flags appended at the end, one after another, but everything is still compiling quite happily.

Using GNU C++ built library in VS C++ project

I'm trying to implement an open source library that is built using the GNU compiler. (namely, this: https://github.com/mjwybrow/adaptagrams )
I've tried opening and building that source code using VSC++ 6, but it results in over a thousand errors due to the strict nature of the VS compiler I guess. And rather then go through every error and try fix it myself, I was wondering if it's possible to just include the .lib if it is built with the GNU compiler?
EDIT:
Included in the source code linked above is an autogen.sh file.
mkdir -p m4
autoreconf --install --verbose
automake -a --add-missing
./configure
make
Running that with Cygwin results in a few .a library files to be created, which are unusable in VS. Is it ok to just rename these to .lib files?
I've found some stuff online about how to use GCC and create a DLL, but my problem is that I don't know enough about the GNU compiler or makefiles, or the source code in general to be able to change it right now.
Does anybody have any clues on what exactly I'd need to change to get it right? Or even better, has anyone created a DLL using this source code already that would be able to pass it on to me, or let me know what I have to do?
Or could anyone point me towards a similar library that would be compatible with visual studio?
No; you can however build the .dll file with gcc and use the .dll from msvc (with either a hand-crafted include file or a properly formatted one from the beginning, with platform specific import/export macros on top).

`missing-syscalls' error during kernel compilation

These are the steps I am doing to compile the linux source on my machine :
1. Copy the config file from /boot to /usr/src/kernels/2.6.29.4-167.fc11.i586/ directory
2. make oldconfig
3. make
Step 3 fails with the following error :
make[1]: *** No rule to make target `missing-syscalls'. Stop.
Compiling on a x86 box.
Any suggestions ?
Please feel free to close this question if it does not belong here.
As archaic as it may sound it appears that currently in order to get kernel source on a system you have to manually select the source you want. One supposes that people don't build kernels as often as they used to and of course you may want to develop a kernel that does not match the version that you are running..
So for example I wanted to install VBox on my CentOS 6.2 box and while most kernel modules can be compiled without complete sources this update failed.
So I found this wiki page:
http://wiki.centos.org/HowTos/I_need_the_Kernel_Source
It doesn't list 6.2 and the naming conventions have changed on the final directory name so to get the 6.2 kernel source you go to http://vault.centos.org/6.2/updates/Source/ and select the version you want. If you want source for a different version go to http://vault.centos.org/ and navigate from there.
The docs recommend against doing an rpm-build on the kernel sources.
Make a new config file. Maybe the old one isn't working?
I have not been able to answer why this error happens :
Step 3 fails with the following error : make[1]: *** No rule to make target `missing-syscalls'. Stop.
But I was able to compile the vanilla version fine, without the above error.
I asked the same question on serverfault as well, which has a more detailed explanation of the steps taken : https://serverfault.com/questions/61354/missing-syscalls-error-during-kernel-compilation
since kernel 3.x.x this message appears if trying to build external modules having only single Makefile prepared.
Instead, according to this manual,
splitting into Kbuild (where all the source files are listed, example):
obj-m := module_source.c
and simple Makefile (having only default make directive, example):
default:
$(MAKE) -C $(KDIR) M=$$PWD
will solve the problem.
just in case, external module build directive would be following:
make -C <kernel source path> -M=<module source folder>
example: make -C . -M=extra/

Resources