Unknown CMake command "collect" - c

I need help in building a binary file with the help of cmake toolchain file
I have the below structure
lib also included with header files
examples/dir1/dir2/dir3/dir4/demo -- will contain the Demo by using those src nd header files.
I was able to build library(.a) file with the include and lib
But not knowing how would I able to build the binary for the demo
****toolchain file**********
add_subdirectory(examples)
error:
CMake Error at examples/CMakeLists.txt:1 (collect):
Unknown CMake command "collect".
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

Related

Using protoc inside CMakeLists from a non-standard directory gives "cannot open shared object file: No such file or directory" error

I have a C application using CMake to generate Makefiles on Linux. The application contains .c as well as .proto files. Now I need to genearte .pb-c.c and .pb-c.h using protoc command in the CMakeLists.txt so that when I do cmake . the cmake generates the corresponding .pb-c and .pb-h. The protoc is used as:
execute_process(COMMAND bash -c "${PROTOC_PATH} --c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto")
The problem is that my protoc binary and related .so file is not in /usr/bin and /usr/lib or /usr/local/bin and /usr/local/lib. They are in a directory inside the project - $HOME/project-name/dependencies/bin/protoc and $HOME/project-name/dependencies/lib/libprotobuf.so.12
Due to this I am getting error - error while loading shared libraries: libprotobuf.so.12: cannot open shared object file: No such file or directory
But if I give the command as
execute_process(COMMAND bash -c "protoc--c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto") and run cmake . then it works fine as linker is able to get the .so file from /usr/lib
Mentioned below is a part of my CMakeLists.txt file
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${PROTOC_LIB_PATH} -L${PROTOC_LIB_PATH} -lprotobuf")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath=${PROTOC_LIB_PATH} -L${PROTOC_LIB_PATH} -lprotobuf")
execute_process(COMMAND bash -c "${PROTOC_PATH} --c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto")
But it's not working due to aforementioned error.
Also for those who might say it's a duplicate I have looked into and tried the following SO questions:
Turning on linker flags with CMake
I don't understand -Wl,-rpath -Wl,
CMake link to external library
Does cmake have something like target_link_options?
CMAKE RPATH not working - could not find shared object file
https://serverfault.com/q/279068/435497
How to add linker flag for libraries with CMake?
https://serverfault.com/a/926072/435497
If you do not have a special use case, you do not need to call protoc yourself. Let CMake do this for you.
Have a look at: https://cmake.org/cmake/help/v3.16/module/FindProtobuf.html
and Cmake : find protobuf package in custom directory
I found this link which has a script showing how to create a PROTOBUF_GENERATE_C function which can then be used to generate the .pb-c abd .pb-h files.
From the above script I got the idea to make use of find_program which is similar to find_library in a way that it lets you pass the PATHS/PATH option so that CMake looks for the required program in the mentioned path.

Where to put libwebsocket.h file

I'm trying to test the libwebsockets API https://github.com/warmcat/libwebsockets/tree/master/minimal-examples/api-tests/api-test-lws_tokenize
Whenever I type
cmake . && make
to build the code. I got following error.
Scanning dependencies of target lws-api-test-lws_tokenize
[ 50%] Building C object CMakeFiles/lws-api-test-lws_tokenize.dir/main.c.obj
C:\Users\pro12\Desktop\New folder (2)\libwebsockets\minimal-examples\api-
tests\api-test-lws_tokenize\main.c:16:27: fatal error: libwebsockets.h: No
such file or directory
#include <libwebsockets.h>
^
compilation terminated.
My question is where to add libwebsockets.h file?
I have mingW installed and i'm using gcc compiler. I have libwebsockets build downloaded from here https://ci.appveyor.com/project/lws-team/libwebsockets which is placed at C:\Program Files (x86)/libwebsockets

Libdvbcsa, missing header files

I have a problem i cannot solve.
Library repository
I am trying to run test .c files in this library, I have installed the files however when I run this on mac:
gcc testbitslice.c
I get this error
fatal error: dvbcsa_pv.h: No such file or directory
#include "dvbcsa_pv.h"
the testbitslice.c file calls the header files as follows
#include <dvbcsa/dvbcsa.h>
#include "dvbcsa_pv.h"
When I checked urs/local/include there are one file under dvbcsa folder which is dvbcsa.h. But there is no file called dvbcsa_pv.h. I don't understand the problem. I don't get error while installing with ./bootstrap or ./configure and make, make install commands.
Then, I manually copy/paste header files from package folder to usr/local/include, this time it gives error as
Undefined symbols for architecture x86_64
Is the problem related to installation or something else? I would appreciate if you could help me
I have found out the problem. I just had to show the library directory i want to use using:
-I/Users/bill/Desktop/libdvbcsa-master/src/dvbcsa
and it works.

CMake configuration

I have a simple C project structure:
proj/
src/
docs/
build/
tests/
lib/
Trying to write a suitable CMake file.
My attempt so far: http://pastebin.com/846ZzUev
CMake Error at CMakeLists.txt:6 (PROJECT_SOURCE_DIR):
Unknown CMake command "PROJECT_SOURCE_DIR".
-- Configuring incomplete, errors occurred!
See also "/path/to/proj/CMakeFiles/CMakeOutput.log".
*How do I: *
Force a custom compiler.
Auto-include all library folders with automatic file detection.
(PROJECT_ROOT/src and PROJECT_ROOT/lib)
Unknown CMake command "PROJECT_SOURCE_DIR". - PROJECT_SOURCE_DIR isn't a command, it's a variable. It looks like you're trying to tell CMake where your code lives - the usual way of doing this is simply placing the CMakeLists.txt file in root of the project.
"Force a custom compiler." - This is covered in the FAQ.
"Auto-include all library folders with automatic file detection." - You mean something like described in this answer(more discussion here)? The idiomatic CMake way of doing this would be to explicitly list the targets with their source files.

GNU C compiler cannot locate header file

I have installed a package libstree on my machine (x86_64/Redhat Linux).
Have followed the instructions ( ./configure --prefix=/usr; make check; make install) to install the package.
Have checked that the relevant header files are in the /usr/include and /usr/lib directories.
However when I try to compile a test program I get an error message:
test.c:6:25: fatal error: lst_structs.h: No such file or directory
compilation terminated.
lst_structs.h is present in the /usr/include/stree directory.
Anyone have any thoughts as to why the GNU C compiler cannot locate the header file?
As it's in an /include sub-directory, you need to explicitly mention it (see comments above), or adjust your lib include path, as outlined on this old stackoverflow post:
How to add a default include path for gcc in linux?

Resources