How to compile .C files in Eclipse using GCC - c

I have a C project in Eclipse that compiles without any errors. But due to client requirements, I have renamed my source files into .C and .H, e.i, uppercase file extensions. But when I build my project, Eclipse shows:
**** Build of configuration Debug for project test_harness ****
Nothing to build for project test_harness
The logs show that GCC didn't recognized the files with uppercase extensions as C source files. Upon searching, I found out that the .C files are actually C++ files.
But is there a way to tell Eclipse to compile .C files using GCC instead of G++?

Related

How to compile the LIBVLC example code on windows using gcc

I want to build the libvlc example (https://wiki.videolan.org/LibVLC_Tutorial) so i downloaded the sources and also copied libvlc.dll and libvlccore.dll (from my vlc installation) into the current directory. Then i try to compile it by issuing
gcc example.c -o example -I./include -L./lib -L./ -llibvlc
but get the error
example.c:3:22: fatal error: vlc/vlc.h: No such file or directory
#include <vlc/vlc.h>
^
I hope this is enough information, i controlled all paths and files twice. Thank you in advance.
you need vlc sdk, not just files from vlc source code ;
you need dll files for your already compiled application, but for build you need .lib files - also part of sdk;
for this you need to build them - for this step refer to https://medium.com/#tobias.strg/compiling-vlc-3-x-in-2020-a390c6a73c24;
no doubt you can use some nigthly builds of vlc (check for zip files with "debug" suffix) https://artifacts.videolan.org/vlc-3.0/nightly-win64/20220420-0220;
after you got sdk pack for your platform you can compile - pointing to headers files from sdk, and linking with libs from sdk;

How to compile a Firmware project by using command prompt

I am looking for a bunch of code lines to compile a firmware project by using command prompt. I found for compiling just a .c file it's enough to write gcc -o filename.c.
However my project is a folder with a number of .c files .h files and 3 other formats and I have no idea how to run and compile the whole folder by cmd.
Here is content of project:
Would you give me some advice on what are related commands for this?
Thanks

Linking shared dll library cmake clion project

I currently have two C projects on Clion with cmake. One of the projects is named "sharedLibsDemo" and I am trying to create a shared library in this project. In the other project I want to use the library that was created by the "shared" project.
Currently, in the "sharedLibsDemo" project I have the following cmake:
cmake_minimum_required(VERSION 3.7)
project(sharedLibsDemo)
set(CMAKE_C_STANDARD 11)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
set(SOURCE_FILES shared.c shared.h main.c)
add_library(shared SHARED ${SOURCE_FILES})
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(shared # generates the export header shared_EXPORTS.h automatically
BASE_NAME shared
EXPORT_MACRO_NAME SHARED_EXPORTS
EXPORT_FILE_NAME shared_EXPORTS.h
STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)
set(EXEC_FILES main.c)
add_executable(myexe ${EXEC_FILES})
target_link_libraries(myexe shared)
However, this cmake only creates the shared_EXPORTS.h, libshared.dll, and libshared.dll.a` files.
I managed to create the .lib file using Mingw itself and put all of these files including the .h file of the source code into one folder and placed the folder in the root folder of the second project in order to use it.
However, I've looked everywhere to find a way to link the library into the second project's executable. The documentation for cmake itself assumes I have a tonne of knowledge which I don't. Is there any list of commands that I can use to finally link my library. I have already tried the generic answer of "use find_package() or target_link_libraries" to no avail.
EDIT 1
The following is the contents of shared.h :
#include "shared_EXPORTS.h"
#ifndef SHAREDLIBSDEMO_LIBRARY_H
#define SHAREDLIBSDEMO_LIBRARY_H
void SHARED_EXPORTS sharedHello(void);
#endif
As per the suggestion of #Shmuel H. I placed the shared.h shared.c and the cmakelist.txt for the shared project into a folder in the project that I want to include the library in. And I used add_subdirectory() and target_link_libraries().
The following is the CMakeLists.txt for the project:
cmake_minimum_required(VERSION 3.7)
project(projectFiles)
set(CMAKE_C_STANDARD 11)
include_directories(src ${maker_INCLUDE_DIR})
set(SOURCE_FILES src/nv_runner/main.c src/FactParser/FactParser.c src/FactParser/FactParser.h src/Utils/Utils.c src/Utils/Utils.h src/nv_runner/main.h)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_package(maker REQUIRED)
include_directories(${maker_INCLUDE_DIR})
set(LIBSHARED_LOCATION ${PROJECT_SOURCE_DIR}/libshared)
add_subdirectory(libshared)
include_directories(${LIBSHARED_LOCATION})
add_executable(${PROJECT_NAME} ${SOURCE_FILES} src/FactParser/FactParser.c src/FactParser/FactParser.c src/FactParser/FactParser.h src/nv_runner/main.h)
target_link_libraries(${PROJECT_NAME} ${maker_LIBRARY})
target_link_libraries(${PROJECT_NAME} shared)
At first, I had to remove the SHARED_EXPORTS macro from the sharedHello function and the shared_EXPORTS.h include in shared.h because otherwise it would not recognize the function for use in other files. But when I ran the program I got this result:
Process finished with exit code -1073741515 (0xC0000135)
EDIT 2
Project setup image
In the screenshot, I've taken all the necessary files from the shared project, placed it in a directory in the current project and marked the directory as a Library. The cmake can be seen in the image. With this setup, whenever I run my program, it just crashes with the error seen in the image.
I found out what the issue was. I did not know that the dll had to be in the same folder as the exe, that's why the program was not executing. Once I placed the .dll file inside the exe folder, it worked.
Credit goes to this question for helping me identify the issue: C++ running file with included library failes without compiling error (CMake / CLion)
And I found out that .lib files are only necessary for MSVC compiler. MinGW uses the .dll.a file; replacing .lib. This post lead me to finding this out: Compatibility of *.dll *.a *.lib *.def between VisualStudio and gcc
Please correct me if I'm wrong however. Here is an image of my current project and cmake setup

Force C compiler for extension capital C in Eclipse CDT

I'm having legacy Makefiles and would like to transfer them into Eclipse CDT Projects. Coming from windows, they have mixed .c as well as .C as extensions for C sources (while eclipse normally would treat capital ".C" as c++ files).
As they are checked into source control I'd like to avoid the hassle of renaming the source files.
As the files are linked into the workspace, I tried renaming the link to .c (leaving the target/original file as ".C"). CDT won't care and invoke the C++ compiler. Even worse, when I right-click on the file I get the settings for (only) the C compiler but what I change is irrelevant because still the C++ compiler with the project wide C++ settings is invoked.
Now, if there are only C files in the project I can set the project C++ settings under "Miscellaneous" to use -xc -std=c99 etc. and effectively force the g++ to behave like a proper C compiler - Which is not really beautiful and completely fails when there are other real .cpp files to be compiled as C++ within the same project.
Also, using project settings under C/C++ General/File Types and setting ".c" and ".C" to "C source file" doesn't seem to bother the CDT...
Am I overlooking something? Is this far outside the scope of CDT?

Eclipse: Add external lib for c project Not working

I have done the following:
Create new c project (Makefile Project with Existing Code)
Added a build variable that my Makefile complained about
Now my source .c file complains about #include files because it does not know where the lib folder is,I tried adding lib folder to library path (DID NOT WORK).
How can I link my project to an external lib folder so that my .c source file can read the .h files needed for the #include?
I added the library path to Paths and Symbols->Includes BUT when I go back to the project it only shows the root folder and nothing inside it. Do I also have to add each individual .so lib file?
Answered here : How do you add libraries to Eclipse CDT? (No such file or directory)
#cyfur01 has the best answer :
What to add depends on what you are trying to include. In the case of
Boost, there are a number of header-only libraries, and there are some
libraries that require linking in static/shared-object libraries
(e.g., serialization). Header-Only Libraries
For header-only libraries, you just need to include the base directory
of all the header files. With gcc, you add the directory using the -I
flag (e.g., -I C:/path/to/boost_52_0). With a managed makefile project
in Eclipse, you can accomplish the same using Properties > C/C++ Build
Settings > Tool Settings > GCC C++ Compiler > Directories Static/Shared-Object Libraries
For static/shared-object libraries, you have to specify two options:
-l --> The name of the library, less the 'lib' prefix and the file suffix (e.g., libboost_serialization.dll -> boost_serialization
-L --> The directory to look for the library file in. This is only needed if the library is on a non-standard path.
As #Chris pointed out, for a managed makefile project, both of these
options can be set through Properties > C/C++ Build > Settings > Tool
Settings > GCC C++ Linker > Libraries
ok so I figured it out:
(1) At the start I had a source.c and a MAKEFILE
(2) Create new c project (Makefile Project with Existing Code)
(3) MAKEFILE complained about a variable so I added it to environment variable
(4) #include files complained so I added external library like so
(a) I located my library path and found that there is a folder before /lib called include
(b) The include folder had a list of header files
(c) So I added the path to the include folder NOT the lib folder under paths and symbols include
WORKED LIKE A CHARM!

Resources