Eclipse Makefile Error

Need help with C, C++, perl, python, etc?

Eclipse Makefile Error

Postby Ciocan.Cosmin » 2016-07-22 12:54

Hello guys. I need some help with solving an error. I was trying to create a simple bluetooth server using the library bluez-5.31 . I am using eclipse on Raspbian Jessie which is similar to Debian but I have little to no experience with either one. I tried fixing it for a couple days now and nothing seems to be working so i really need some help...
This is the error description:
Code: Select all
error 1:   make:*** [Bluetooth Server 2]Error 1               Resource: Bluetooth Server 2      
error 2:    recipe for target 'Bluetooth Server 2' failed      Resource: makefile                Path: /Bluetooth Server 2/Debug      Location: line 45

where "Bluetooth Server 2" is the name of the project


This is main:
Code: Select all
#include "/usr/include/stdint.h"
#include "/usr/include/bluez-5.31/lib/bluetooth.h"
#include "/usr/include/bluez-5.31/lib/hci.h"
#include "/usr/include/bluez-5.31/lib/hci_lib.h"
#include "/usr/include/bluez-5.31/lib/rfcomm.h"

int main(int argc, char **argv)
{
   struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
   char buf[1024] = { 0 };
   int s, client, bytes_read;
   unsigned int opt = sizeof(rem_addr);

   //allocate socket
   s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

   //bind socket to port 1 of the first available adapter

   bdaddr_t tmp = {0,0,0,0,0,0};

   loc_addr.rc_family = AF_BLUETOOTH;
   loc_addr.rc_bdaddr = tmp;
   loc_addr.rc_channel = 1;
   bind(s, (struct sockaddr* )&loc_addr, sizeof(loc_addr));

   //put socket into listening mode
   listen(s, 1);

   //accept one connection
   client = accept(s, (struct sockaddr *)&rem_addr, &opt);

   ba2str( &rem_addr.rc_bdaddr, buf );
   fprintf( stderr, "accepter connection from %s\n", buf);
   memset( buf, 0, sizeof(buf));

   //read data from the client
   bytes_read = recv(client, buf, sizeof(buf), 0);
   if( bytes_read > 0 )
   {
      printf("received [%s]\n", buf);
   }

   //close connection
   //close(client);
   //close(s);
   return 0;
}


This is the make file:
Code: Select all
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables

# All Target
all: Bluetooth\ Server\ 2

# Tool invocations
Bluetooth\ Server\ 2: $(OBJS) $(USER_OBJS)
   @echo 'Building target: $@'
   @echo 'Invoking: GCC C++ Linker'
   g++ -L/usr/include/ -bluez-5.31 -o "Bluetooth Server 2" $(OBJS) $(USER_OBJS) $(LIBS)
   @echo 'Finished building target: $@'
   @echo ' '

# Other Targets
clean:
   -$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) "Bluetooth Server 2"
   -@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets


And this is what changes i made to project properties
Code: Select all
- C/C++ Build >> Settings >> Tool Settings >> GCC C++ Linker >> Miscellaneous: In the linker flags box i wrote: "-bluez-5.31"
- C/C++ Build >> Settings >> Tool Settings >> GCC C++ Linker >> Libraries: Added " "bluez-5.31" " in -l
- C/C++ Build >> Settings >> Tool Settings >> GCC C++ Linker >> Libraries: Added " /usr/include " in -L
Ciocan.Cosmin
 
Posts: 2
Joined: 2016-07-22 12:40

Re: Eclipse Makefile Error

Postby tomazzi » 2016-07-22 21:48

1. This is a very bad idea to use spaces in names of programs/projects.
2. Apparently there's a bug in eclipse (which may not be a bug, but at least unwanted/unexpected/undocumented behavior):
Code: Select all
g++ -L/usr/include/ -bluez-5.31 -o "Bluetooth Server 2" $(OBJS) $(USER_OBJS) $(LIBS)

"-bluez-5.31": definitely there's no such option in g++, it should be: "-lbluez-5.31". The eclipce should add the '-l' prefix.
But in fact this wouldn't solve the problem, because the BlueZ shared library is named libbluetooth.so(*), so the correct option would be:
Code: Select all
g++ -L/usr/include/ -lbluetooth -o "Bluetooth Server 2" $(OBJS) $(USER_OBJS) $(LIBS)

Regards.

(*) in Wheezy at least, I didn't checked if it have changed Jessie.
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: Eclipse Makefile Error

Postby Ciocan.Cosmin » 2016-07-23 17:20

I followed what you said exactly and it worked! Many thanks!
Ciocan.Cosmin
 
Posts: 2
Joined: 2016-07-22 12:40

Re: Eclipse Makefile Error

Postby Arthos » 2016-09-24 18:17

tomazzi wrote:1. This is a very bad idea to use spaces in names of programs/projects.
2. Apparently there's a bug in eclipse (which may not be a bug, but at least unwanted/unexpected/undocumented behavior):


Its explained in a bit more detail here

http://unix.stackexchange.com/questions ... a-filename

I wouldn't call it a bug its just one of the many fussy ways *nix systems behave.
root is my account - http://www.garyshood.com/root/
Arthos
 
Posts: 65
Joined: 2015-05-10 17:38

Re: Eclipse Makefile Error

Postby tomazzi » 2016-09-24 23:04

Arthos wrote:
tomazzi wrote:1. This is a very bad idea to use spaces in names of programs/projects.
2. Apparently there's a bug in eclipse (which may not be a bug, but at least unwanted/unexpected/undocumented behavior):


I wouldn't call it a bug its just one of the many fussy ways *nix systems behave.


So do I - I've said that missing '-l' prefix looks like a bug in Eclipse...

But, problems with spaces in file names have *nothing* to do with those "fussy ways *nix systems behave" - exactly the same problems are existing in winblows, mac and in fact any operating system which have ever existed on this planet.

Why?
Because spaces are used also to separate commands and arguments, both in terminals and script interpreters - so users are forced to pay special attention to distinguish file-name-space from command-line-space.
This is just pain in the ass, and there's no even a single benefit.

Use underscores if You absolutely have no idea how_to_name_your_files ;)

Regards.
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable