|
Vaclav_ wrote: I have quit checking the actual file descriptor because perror gives a more information when it fails.
This could be a problem: perror() prints the associated error string with the current errno , but a successful library call does not reset errno to zero. If you're going to rely on perror() , and by extension errno , you need to make sure you set errrno to zero before any library call that might set errno . Otherwise, you could be getting invalid error information. Every library function I can think of will return a value that will indicate that it failed (e.g. -1 for open() , or NULL for fopen() , etc). You really should be testing the return value for failure before checking perror()
|
|
|
|
|
I have started doing both checks - return values and errno.
If I understand perror it does something special when errno is zero.
Perhaps I will try to keep track of errno.
There are two "weird" behaviour I am unable to grasp.
I am definitely getting different responses when running SAME code on X86 and ARM7.
I am working on that to make sure.
Even if errno is NOT changed between calls, getting "Invalid parameters" is puzzling when the parameters are SAME in both calls.
Here is a proof you are on the right track !
Code
socket_fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
#ifdef TRACE
cout << "Socket errno " << dec << errno << " @line " << __LINE__ << endl;
perror("STATUS allocate socket ");
this call sets the errno to 22 - AFTER perror is executed with errno being set to 0 success!
cout << "socket_fd " << dec << socket_fd << endl;
this call
cout << "Socket errno " << dec << errno << " @line " << __LINE__ << endl;
#endif
here the errno is still set to 22 !
socket_fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
#ifdef TRACE
cout << "Socket errno " << dec << errno << " @line " << __LINE__ << endl;
perror("STATUS allocate socket ");
cout << "socket_fd " << dec << socket_fd << endl;
cout << "Socket errno " << dec << errno << " @line " << __LINE__ << endl;
exit(-1);
#endif
Output
SERVER_X86_228
RPI_ARM
date version Feb 29 2020
test time 13:37:53
STATUS allocate socket : Success
BREAK @line 47
Socket errno 0 @line 61
socket_fd 3
Socket errno 22 @line 64
Socket errno 22 @line 72
socket_fd 4
Socket errno 22 @line 75
STATUS allocate socket : Invalid argument
modified 29-Feb-20 14:47pm.
|
|
|
|
|
Good point, I totally forgot about that.
|
|
|
|
|
perror(3) - Linux manual page[^]
Add a direct quote from man
When a system call fails, it usually returns -1 and sets the variable
errno to a value describing what went wrong. (These values can be
found in <errno.h>.) Many library functions do likewise. The
function perror() serves to translate this error code into human-
readable form. Note that errno is undefined after a successful
system call or library function call: this call may well change this
variable, even though it succeeds, for example because it internally
used some other library function that failed. Thus, if a failing
call is not immediately followed by a call to perror(), the value of
errno should be saved.
And I am not the only one using perror wrong. Take this gem
I have commented out here just to show the original code.
This "example" shows why some coders do not check the call result.
errcode = getaddrinfo("z_desktop", NULL, &hints, &res);
if (errcode != 0) { perror("STATE getaddrinfo");
return -1;
}
|
|
|
|
|
I have moved the code to run on RPi ARM and have NO ISSUES!
I shall go ahead and finish my experiment passing data using bluetooth on SAME hardware,
Perhaps when I get it fully working it will be easier to find why it fails on X86.
Thanks four your help.
|
|
|
|
|
how do you run a console program with arguments on windows 7? when you run it from the shell the window disapears instantly.
|
|
|
|
|
|
|
Run it in a cmd window, just like in a Linux terminal.
|
|
|
|
|
notice taken, thank you Richard
|
|
|
|
|
use
cmd /k yourapp - the /k prevents the window from closing once the app has finished running.
|
|
|
|
|
I`m learning assembler. I need advice for picking a compiler.
|
|
|
|
|
The best starting point would be the manual for the assembler language that you are learning.
|
|
|
|
|
Thanks for feedback. I`m not using a manual as reference, I`m learning on my own.
modified 21-Feb-20 9:27am.
|
|
|
|
|
Well you must be extremely talented.
|
|
|
|
|
thank`s for your compliment, I`m no different than any other person though.
|
|
|
|
|
The point I was trying to make is that you need to make use of the learning materials that are available. And in the age of the internet there are millions of them.
|
|
|
|
|
I do what I can but I haven`t found exactly what I was looking for, though that`s only because I wasn`t looking for the right thing maybe. I know there is tons of material out there but I don`t trust them unless I`m specifically pointed to a resource by someone.
Richard thanks for your useful feedback.
modified 21-Feb-20 14:05pm.
|
|
|
|
|
Hi,
I had a nicely operating cross compilation tool setup ( see the article I wrote about it Toolset to Cross Compile/Remote Debug Raspberry from Windows Host[^] )
Today I tried to run a python script but it needed python 3.7. I did not have that in the Msys32 setup I was using. After some searching I tried to put the Msys32 configuration up to date but it completely failed and became totally inoperable. It was not even possible to start the Mingw32 shell in it any more.
I Also had an Msys64 setup available and tried to update that one and it worked perfectly. I installed python 3.8.1.1 and was able to run the python script from within the updated Mingw64 shell. The Msys64 setup also contains a Mingw32 shell which runs equally well.
So far so good but now I have a completely different problem: whenever I try to run the make command for my project ( either manually in the Mingw32 or Mingw64 shell or from Visual studio code ) I get a really odd error message:
$ make
mkdir -p build/./main/
The syntax of the command is incorrect.
make: *** [build/./main/hello_world_main.c.o] Error 1
It is the mkdir -p build/./main/ which appears to be the culprit but strangely enough that used to work perfectly and when I type the exact same command from within either the Mingw32 or Mingw64 shell it executes perfectly without the slightest trace of an error message.
For completeness I have included the Makefile content below but this has really thrown a spanner in the works. Does anyone have an idea as to what may be the cause of this?
TARGET_EXEC ?= Hello_world_c
BUILD_DIR ?= ./build
SRC_DIRS ?= ./main
SYSROOT = $(RPIDEV_LOC)/arm-linux-gnueabihf/sysroot
CROSS_COMPILE = $(RPIDEV_LOC)/bin/arm-linux-gnueabihf
CXX = $(CROSS_COMPILE)-g++ --sysroot $(SYSROOT)
CC = $(CROSS_COMPILE)-gcc --sysroot $(SYSROOT) -lpigpio
AS = $(CROSS_COMPILE)-as
AR = $(CROSS_COMPILE)-ar
NM = $(CROSS_COMPILE)-nm
LD = $(CROSS_COMPILE)-ld
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -g
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p
|
|
|
|
|
I can't recall which one it is but there is an option* in make to list everything as it proceeds. That may help to isolate the problem.
*I think -n will process the makefile but not execute the resulting statements
Possibly -p to list everything
|
|
|
|
|
Richard MacCutchan wrote: *I think -n will process the makefile but not execute the resulting statements
Possibly -p to list everything
correct. But you're going to want to do
make -p > make.out 2>&1 and then use an editor to view the results.
$ make -p hello.c | wc -l
1481
$
So that's ~1500 lines for a simple one liner. And then you're going to have to wade through all the rules for everything from c, c++ to lexx/yacc and fortran, etc.
|
|
|
|
|
No big deal with a modern editor to find the key parts.
|
|
|
|
|
Just took a look and it seems that the commands make will process are at or near the top of the file, and then the rules that make used follow e.g.
$ make -p hello > make.out 2>&1
$ head -20 make.out
cc hello.c -o hello
# GNU Make 4.2.1
# Built for arm-unknown-linux-gnueabihf
# Copyright (C) 1988-2016 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.
# Make data base, printed on Tue Feb 4 12:02:00 2020
# Variables
# automatic
<D = $(patsubst %/,%,$(dir $<))
# automatic
?F = $(notdir $?)
# default
.SHELLFLAGS := -c
# environment
XDG_SESSION_CLASS = user
$
Trying to figure out the rules that make used to generate the commands can sometimes be challenging, though.
|
|
|
|
|
As Charles Petzold famously wrote in "Programming Windows 3.1", "No one said it would be easy".
|
|
|
|
|
If it was easy, any idiot could do it. The main problem, as I see it, is many of them think they can
|
|
|
|