Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine Compile Failed #846

Closed
forstef opened this issue Apr 18, 2020 · 14 comments
Closed

Alpine Compile Failed #846

forstef opened this issue Apr 18, 2020 · 14 comments

Comments

@forstef
Copy link

forstef commented Apr 18, 2020

Describe the bug
I compile it in alpine but failed:
屏幕快照 2020-04-18 下午7 23 33
屏幕快照 2020-04-18 下午7 23 42
屏幕快照 2020-04-18 下午7 23 53

/github.com/paho.mqtt.c # make
mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
mkdir -p build
sed -e "s/@CLIENT_VERSION@/1.3.2/g" -e "s/@BUILD_TIMESTAMP@/Sat Apr 18 11:18:58 UTC 2020/g" src/VersionInfo.h.in > build/VersionInfo.h
cc -g -fPIC -D_GNU_SOURCE -Os -Wall -fvisibility=hidden -Ibuild -DPAHO_MQTT_EXPORTS=1 -o build/output/libpaho-mqtt3c.so.1.3 src/Messages.c src/Tree.c src/MQTTProtocolClient.c src/Base64.c src/SocketBuffer.c src/utf-8.c src/MQTTReasonCodes.c src/StackTrace.c src/Log.c src/MQTTClient.c src/SHA1.c src/MQTTPacket.c src/OsWrapper.c src/Clients.c src/WebSocket.c src/MQTTPersistence.c src/Thread.c src/Socket.c src/MQTTPacketOut.c src/MQTTTime.c src/MQTTPersistenceDefault.c src/MQTTProperties.c src/MQTTProtocolOut.c src/LinkedList.c src/Heap.c -shared -Wl,-init,MQTTClient_init -Wl,--start-group -lpthread -lanl -Wl,--end-group -Wl,-soname,libpaho-mqtt3c.so.1
src/Heap.h:55:24: error: expected declaration specifiers or '...' before string constant
55 | #define free(x) myfree(FILE, LINE, x)
| ^~~~~~~~
src/Heap.h:55:34: error: expected declaration specifiers or '...' before numeric constant
55 | #define free(x) myfree(FILE, LINE, x)
| ^~~~~~~~
In file included from src/StackTrace.c:21:
src/Clients.h:59:18: error: field 'lastTouch' has incomplete type
59 | START_TIME_TYPE lastTouch; /> used for retry and expiry /
| ^~~~~~~~~
src/Clients.h:79:18: error: field 'lastSent' has incomplete type
79 | START_TIME_TYPE lastSent;
| ^~~~~~~~
src/Clients.h:80:18: error: field 'lastReceived' has incomplete type
80 | START_TIME_TYPE lastReceived;
| ^~~~~~~~~~~~
src/Clients.h:81:18: error: field 'lastPing' has incomplete type
81 | START_TIME_TYPE lastPing;
| ^~~~~~~~
src/StackTrace.c: In function 'StackTrace_entry':
src/StackTrace.c:112:34: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
112 | Log_stackTrace(trace_level, 9, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
| ^
src/StackTrace.c: In function 'StackTrace_exit':
src/StackTrace.c:136:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
136 | Log_stackTrace(trace_level, 10, (int)my_thread->id, my_thread->current_depth, name, line, NULL);
| ^
src/StackTrace.c:138:36: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
138 | Log_stackTrace(trace_level, 11, (int)my_thread->id, my_thread->current_depth, name, line, (int
)rc);
| ^
In file included from src/Clients.c:24:
src/Clients.h:59:18: error: field 'lastTouch' has incomplete type
59 | START_TIME_TYPE lastTouch; /
> used for retry and expiry */
| ^~~~~~~~~
src/Clients.h:79:18: error: field 'lastSent' has incomplete type
79 | START_TIME_TYPE lastSent;
| ^~~~~~~~
src/Clients.h:80:18: error: field 'lastReceived' has incomplete type
80 | START_TIME_TYPE lastReceived;
| ^~~~~~~~~~~~
src/Clients.h:81:18: error: field 'lastPing' has incomplete type
81 | START_TIME_TYPE lastPing;
| ^~~~~~~~
In file included from src/WebSocket.h:20,
from src/WebSocket.c:30:
src/Clients.h:59:18: error: field 'lastTouch' has incomplete type
59 | START_TIME_TYPE lastTouch; /> used for retry and expiry */
| ^~~~~~~~~
src/Clients.h:79:18: error: field 'lastSent' has incomplete type
79 | START_TIME_TYPE lastSent;
| ^~~~~~~~
src/Clients.h:80:18: error: field 'lastReceived' has incomplete type
80 | START_TIME_TYPE lastReceived;
| ^~~~~~~~~~~~
src/Clients.h:81:18: error: field 'lastPing' has incomplete type
81 | START_TIME_TYPE lastPing;
| ^~~~~~~~
In file included from src/MQTTPersistence.h:27,
from src/MQTTPersistence.c:29:
src/Clients.h:59:18: error: field 'lastTouch' has incomplete type
59 | START_TIME_TYPE lastTouch; /
> used for retry and expiry */
| ^~~~~~~~~
src/Clients.h:79:18: error: field 'lastSent' has incomplete type
79 | START_TIME_TYPE lastSent;
| ^~~~~~~~
src/Clients.h:80:18: error: field 'lastReceived' has incomplete type
80 | START_TIME_TYPE lastReceived;
| ^~~~~~~~~~~~
src/Clients.h:81:18: error: field 'lastPing' has incomplete type
81 | START_TIME_TYPE lastPing;
| ^~~~~~~~
make: *** [Makefile:254: build/output/libpaho-mqtt3c.so.1.3] Error 1
/github.com/paho.mqtt.c #

To Reproduce
Fresh alpine:latest docker image.
apk add openssl-dev
make

** Environment (please complete the following information):**

  • OS: latest alpine docker image in Mac mojave
@icraggs
Copy link
Contributor

icraggs commented Apr 18, 2020

Perhaps you could find out what the difference is between Alpine Linux and the other Linux distributions on which the build works, and suggest some changes that would make it work?

@forstef
Copy link
Author

forstef commented Apr 20, 2020

OK, I'll try.

@icraggs
Copy link
Contributor

icraggs commented Apr 21, 2020

Some of these errors are fixed in the response to #851, which the latest source includes.

@icraggs
Copy link
Contributor

icraggs commented Apr 22, 2020

If you try again with the latest 1.3.2 source, we should be closer.

@forstef
Copy link
Author

forstef commented Apr 22, 2020

1587560949656
It seems still have some errors, but much less than before. and it seems the complier doesn't support LINE and FILE macros. I will try to figure it out when I was not busy.

@icraggs
Copy link
Contributor

icraggs commented Apr 23, 2020

The FILE and LINE macros are standard C, I don't know why they aren't there.

You can build with the NOSTACKTRACE or HIGH_PERFORMANCE compiler definitions which will build without stack tracing, and avoid the need for these macros. That should allow it to build.

@forstef
Copy link
Author

forstef commented Apr 23, 2020

It is not The FILE and LINE macros, because
#define malloc(x) mymalloc(FILE, LINE, x)
#define realloc(a, b) myrealloc(FILE, LINE, a, b)

are passed, but not:

#define free(x) myfree(FILE, LINE, x)

@icraggs
Copy link
Contributor

icraggs commented Apr 24, 2020

Did you try building with the compile definitions I suggested?

@icraggs
Copy link
Contributor

icraggs commented Apr 24, 2020

Well I tried it for you. Building with HIGH_PERFORMANCE defined works for me.

@ffontaine
Copy link
Contributor

I can confirm that current version (1.3.2) fails to build on musl due to the redefinition of free. It raises the following build failure on buildroot:

/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before string constant
 void free(void *);
                 ^
/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before numeric constant
 void free(void *);
                 ^
[ 35%] Building C object src/CMakeFiles/common_obj.dir/Base64.c.o
[ 36%] Building C object src/CMakeFiles/common_obj.dir/SHA1.c.o
make[3]: *** [src/CMakeFiles/common_obj.dir/build.make:284: src/CMakeFiles/common_obj.dir/MQTTReasonCodes.c.o] Error 1

Full build log can be found here: http://autobuild.buildroot.org/results/fbe/fbe57a1602fed331ddff3ff3560dce02573816ff/build-end.log

I also confirm that building with -DPAHO_HIGH_PERFORMANCE=TRUE fixes the build (if #861 is applied).

@icraggs
Copy link
Contributor

icraggs commented Apr 24, 2020

@ffontaine why does it object to the redefinition of free, but not malloc or realloc? As far as I remember, this is the first time this has caused a problem in 14 years.

@icraggs icraggs added this to the 1.3.3 milestone May 4, 2020
@icraggs
Copy link
Contributor

icraggs commented May 4, 2020

In the absence of any other way to fix it, I'm going to add a note to the documentation on building with HIGH_PERFORMANCE if this error is met.

@ffontaine
Copy link
Contributor

I tried to investigate this issue. The build failure is raised only by MQTTReasonCodes.c which has been added in version 1.3.0 with 7ea1333, this explains why this error was not raised before.

I checked what was different in this file and I found that the build failure could be fixed by adding an include on MQTTPacket.h before Heap.h. MQTTPacket.h includes Socket.h which in turns includes mutex_types.h which includes pthread.h. Include on pthread.h seems to fix the issue but I don't really understand why for now ...

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue May 11, 2020
Set PAHO_HIGH_PERFORMANCE to disable free redefiniton as suggested by
upstream in eclipse/paho.mqtt.c#846.

This will avoid the following build failure on musl:

/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before string constant
 void free(void *);
                 ^
/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before numeric constant
 void free(void *);
                 ^
[ 35%] Building C object src/CMakeFiles/common_obj.dir/Base64.c.o
[ 36%] Building C object src/CMakeFiles/common_obj.dir/SHA1.c.o
make[3]: *** [src/CMakeFiles/common_obj.dir/build.make:284: src/CMakeFiles/common_obj.dir/MQTTReasonCodes.c.o] Error 1

Fixes:
 - http://autobuild.buildroot.org/results//fbe57a1602fed331ddff3ff3560dce02573816ff

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
@joerg-krause
Copy link

The issue why the build error is only raised for free() is that sched.h only includes a declaration for void free(void *);, but no declaration for malloc() or realloc().

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue May 11, 2020
Set PAHO_HIGH_PERFORMANCE to disable free redefiniton as suggested by
upstream in eclipse/paho.mqtt.c#846.

This will avoid the following build failure on musl:

/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before string constant
 void free(void *);
                 ^
/tmp/instance-1/output-1/host/x86_64-buildroot-linux-musl/sysroot/usr/include/sched.h:80:17: error: expected declaration specifiers or '...' before numeric constant
 void free(void *);
                 ^
[ 35%] Building C object src/CMakeFiles/common_obj.dir/Base64.c.o
[ 36%] Building C object src/CMakeFiles/common_obj.dir/SHA1.c.o
make[3]: *** [src/CMakeFiles/common_obj.dir/build.make:284: src/CMakeFiles/common_obj.dir/MQTTReasonCodes.c.o] Error 1

Fixes:
 - http://autobuild.buildroot.org/results//fbe57a1602fed331ddff3ff3560dce02573816ff

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
(cherry picked from commit e446f5a)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
icraggs added a commit that referenced this issue Aug 3, 2020
@icraggs icraggs closed this as completed Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants