AVSystem / Anjay

C implementation of the client-side OMA LwM2M protocol
Other
189 stars 70 forks source link

Cannot build Anjay 1.15.2 for STM32 #34

Closed kamildoleglo closed 5 years ago

kamildoleglo commented 5 years ago

Hi! I'm not sure if I'm doing something wrong, but I can't build Anjay with version 1.15.2 for STM32 on Mac. Basically the problem is with avs_commons:

[  6%] Built target avs_utils
[  8%] Built target avs_rbtree
[  9%] Built target avs_list
[  9%] Building C object avs_commons/git/compat/threading/src/atomic_spinlock/CMakeFiles/avs_compat_threading_atomic_spinlock.dir/condvar.c.obj
In file included from /Users/kamildoleglo/CLionProjects/Anjay/avs_commons/git/compat/threading/src/atomic_spinlock/condvar.c:17:
/Users/kamildoleglo/CLionProjects/Anjay/avs_commons/git/config/avs_commons_posix_config.h:88:11: fatal error: sys/socket.h: No such file or directory
 # include <sys/socket.h>
           ^~~~~~~~~~~~~~

I use a toolchain with arm-none-eabi-gcc compiler. The toolchain is almost the same as in your tutorial but the target is CortexM4.

Anjay version 1.14.2 compiles successfully, that's why I file this issue. There's probably some option for disabling POSIX support but I can't find it nor the documentation for disabling it

dextero commented 5 years ago

Hi,

arm-none-eabi-gcc does not provide POSIX socket API, which Anjay uses by default. What network stack do you use on your device? Is that LwIP?

If so, you may try passing the (absolute) path to lwip-posix-compat.h file as -DPOSIX_COMPAT_HEADER= argument to CMake (as described in "Note" box in https://avsystem.github.io/Anjay-doc/PortingGuideForNonPOSIXPlatforms.html#networking-api) - this will use LwIP header files instead of POSIX ones, which should help. Please note that #define LWIP_SOCKET 1 and #define LWIP_COMPAT_SOCKETS 1 will need to be defined in lwipopts.h in order for that to work.

kamildoleglo commented 5 years ago

Thanks for the reply, this is probably the issue!

Yes, I use LwIP, but I've got another problem with that. I'd be very grateful if you could point me in the right direction. Basically, I've got a standard CMake project for the STM32 with LwIP and HAL libraries and I don't know how to build Anjay to include it in the project. So according to the documentation:

The preferred method of using Anjay in custom projects is to use CMake find_package command after installing the library: (...)

I get that I should build and install it, no problem. But the lwip-posix-compat.h file, which I should pass as an argument to the CMake, needs some references to the LwIP implementation (which is located in my project). I've tried to include the lwip-posix-compat.h file in my project (and in Anjay project) with absolute paths to the LwIP files from my project, but this doesn't work as the LwIP headers have some relative imports. There are some import to the HAL libraries also. So I get that I should not build Anjay as a standalone library and then install it, but rather build it with my application (including it in the CMakeLists of my project) to have the relative paths resolved correctly. I've also tried this approach, but it failed (eg. because of given unknown export "anjay-targets"). I might have not include it in the CMakeLists correctly however, due to my lack of experience with it. So could you tell me if I'm right that I should build Anjay as a subproject of my application or is there a way to build it outside my app and deal with the relative imports somehow ?

Thanks in advance and sorry to bother you this much

kFYatek commented 5 years ago

If you are trying to include Anjay in another CMake project, not by using find_package(), but by directly including its CMakeLists, you might try using this hack (before including the Anjay subdirectory):

function(install)
endfunction()

This basically masks the install() command used by Anjay's CMakeLists, which causes the errors you're encountering, and replaces it with a no-op. The install() command is not necessary for this kind of operation anyway.

We should probably make it easier to disable installation support in future versions.

kamildoleglo commented 5 years ago

Thanks for your help! I guess I can take it from there, so I'll close this. Have a nice day ;)