assert.h missing when compiling with mingw - c

I am compiling C code with MinGW. The C code is a tcl package/extension.
(using the MinGW compilor, downloaded: mingw-get-inst-20111118.exe)
Compiling the code (e.g. the tcl package) works fine under linux.
I am running "./configure" and using the supplied "Makefile.in".
The problem is that the C code at some point includes "assert.h".
The other header files are fine, e.g. for "string.h" and "stdlib.h".
This is because the TCL sources include a subfolder called "./compat". In this filder the header files are located just in case they are not found somewhere else.
But in the "./compat" folder the file "assert.h" is missing. So I get an error.
I searched for the header file in "c:\MinGW\include" but I did not find "assert.h" there.
Either I copy my own "assert.h" in the "./compat" folder. Or I install some MinGW package that puts some "assert.h" in a subfolder of "c:\MinGW\".
=== SOLUTION: ====
c:\MinGW\include\assert.h
I was the hole time in front of me!!!
My bad! thx.

<assert.h> is part of standard C and included with the base dev package:
Did you download the dev package?
Did you download this?
http://sourceforge.net/projects/mingw/files/MinGW/Base/mingw-rt/mingwrt-3.20/
I don't know about the peculiarities of the tcl package, but if it includes its own assert.h. then you should include on on the Include path, along with the libraries that came with it.
Which IDE are your using?
It seems you downloaded only mingw partially. Download the full development package that is bundled with IDEs like Codelite and Code::Blocks.

Related

C header files are missing after upgrading OSX to Majove 10.14.4

Header files like stdio.h and string.h should be located in /usr/include but they have been removed after upgrading macOS to the current latest version. (10.14.4)
The compile progress may succeed (built-in clang may find these header files elsewhere) but code completion supported by IDEs cannot work without these header files located in the right place.
The following code:
#include <stdio.h>
May be considered error (header file not found).
Fortunately, I found stdio.h by using locate command and it was located in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/, but this directory is not automatically included in CLion.
I'm not sure creating a symbolic link or just copy all these files to /usr/include can work without bad side effects.
Sorry for my self-answer.
But I think this could be useful to others who accidentally upgrade their macOS to 10.14.4.
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Run this command and you can have all header files installed in the right place.

regex.h in dev-c++ (windows )

I am trying to use regex in a c program. i am using windows 10 and Dev-C++ . whenever i add header file for regex i.e.
#include <regex.h>
it gives me error
[error] regex.h: NO such file or directory.
i couldn't figure out how to download and install regex library for c in dev-c++. compiler: TDM-GCC 4.9.2 64-bit Release. Thanks for your help.
I assume there something wrong with the include path during the compilation process. There is a nice expanation of the compilation process of c/c++ applications over here, in case you're interested.
Basically, when compiling a c/c++ application, your compiler, in a first step, scans your source files and replaces all #include <file.h> with the content of file.h it finds in its search path.
Dev-c++ uses MinGW and a port of the GNU compiler collection (gcc) for the compilation process.
Now what you have to do:
Figure out whether regex.h is included in your MinGW installation (Check /usr/include.)
Adapt the include path in dev-c++
Sadly I don't have a computer running Windows nearby making it hard to help with these two steps. To install regex on MinGW this package seems promising.

CMake: Header files cannot be opened

I am working to build a Code Composer Studio project using cmake, which is new to me. It builds successfully under Linux but I am struggling to get it to work under Windows. The cmake command executes without issue, but make fails during the very first C object at the very first #include with the error code
fatal error: could not open source file "stdbool.h" (no directories in search list)
I'm using the libraries included in CCS's compiler (c6000_7.4.15), and that whole folder is included in the CSS project. I include it in cmake as well. In my .cmake file:
set (CCS_ROOT ${CCS_ROOT_V6_WIN} CACHE PATH "code composer install directory")
set(CGT_COMPILER_ROOT ${CCS_ROOT}/tools/compiler/c6000_7.4.15 CACHE INTERNAL "DSP Compiler Root")`
And in the CMakeLists.txt file:
set (COMPILER_INCLUDE ${CGT_COMPILER_ROOT}/include)
INCLUDE_DIRECTORIES ("${COMPILER_INCLUDE}")
Why can the header files not be opened when they're linked in the project and CMake can find them just fine?
EDIT: The directory structure had been changed underneath me, so I took the opportunity to add all of the external files directly into the project to make it completely platform-independent. That way, since the project is managed by our Git repository, users won't have to install the CSL or any other programs to build the project. This also means that paths to libraries and header files will never change between revisions and environments.
Unfortunately, this has not solved my problem. The project continues to build in Linux while failing to ind the very first included header file. I also notice that, under Windows, it cannot find my own header files unless I provide a relative path, e.g. #include "../Common.h" I can get make to find stdbool.h if I provide an absolute path to the compiler directory, but that exposes a web of additional broken links between files.
As a side note, the project builds successfully within Code Composer Studio, so I am assuming that this isn't an issue with my specific Windows environment nor with the code within the project itself.
This seems to be an issue with gcc.exe. I set an environment variable CC to the path of a different compiler (in my case a TI compiler) within my build script and that fixed the problem.

Problems with linking lua statically

I'm trying to link lua statically into my C++ application with VS2012. I downloaded the vs11_lib files off of sourceforge and added linker dependencies for this file, lua52.lib. I'm now getting all sorts of link errors when I try to compile and I'm pretty sure I missed a step. Again, I'm doing this statically since I'd like my application to run stand-alone. Any pointers would be greatly appreciated!
The best way is to build embeddable Lua yourself. Download source files for your desired version, create a static library project in VS2012, copy the source files (*.h and *.c to the VS project, not VS solution) and add all source files to the project, except luac.c and lua.c, which are needed for standalone executable rather than embedded library (and they conflict with each other in one project anyway).
After that compile the release version and you got yourself lua5.x.lib that you can link against. If it's still not working, then the problem might be that you added linker dependencies in the wrong place.
Lua sources can be compiled as C or C++. I figure the lib files you are trying to use are compiled as C and you are including their headers as C++. The outcome would be that the names of the functions are different; ergo, the linking errors.
If you are using a C lib in a C++ file, wrap the lib's header like so:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
For more detailed instructions using Lua with Visual Studio, see this article.
UPDATE:
As, #lhf says in a comment, the newer distributions of Lua provide a C++ header lua.hpp which does the same thing. It is described for older distributions in PIL.

How do I link libraries in Xcode 4?

I'm a complete beginner to Apple's Xcode, but I have followed the Xcode documentation and the advice of a few related questions without success.
I installed GMP to /usr/local/bin, wrote a short program using the library, and compiled with gcc main.c -lgmp. It compiled with no warnings or errors, and the executable worked flawlessly.
I started a new Xcode project (Command Line Tool; Type: C), copied the code to the newly created main.c, and opened the project build settings. From there I set Linking > Other Linker Flags to -lgmp and Search Paths > Library Search Paths to /usr/local/bin. However, the build fails with the preprocessor error "Gmp.h: No such file or directory".
I have tried almost every header imaginable:
#include "gmp.h"
#include <gmp.h>
#include "gmp"
#include "libgmp.a" . . .
This has been my main obstacle over the last three months which has prevented me from learning C. Any help leading me to an eventual solution would be greatly appreciated.
There's a few things you have to set up in your Xcode project. For example, I have gmp installed in /opt/gmp/5.0.2 and I will use that as an example. The actual library is installed into /opt/gmp/5.0.2/lib and the header files into /opt/gmp/5.0.2/include. When installing the library setting the --PREFIX flag to /opt/gmp/5.0.2 would handle this automatically. If you don't set this flag the prefix is usually set to /usr/local by default.
The Other Linker Flags looks right, it should be the name of the library.
Set the Header Search Path to the include directory, in my case /opt/gmp/5.0.2/include.
Set the Library Search Path to the lib directory, in my case /opt/gmp/5.0.2/lib.
Since the header search path has been set, you should now be able to include the header file like this:
#include <gmp.h>
Of course, replace /opt/gmp/5.0.2 with the PREFIX path you used when you installed gmp.
Lastly, you typically don't install libraries to /usr/local/bin, you would install to /usr/localand let any binaries be installed into bin while libraries like these would be installed into lib. Of course any path scheme would work, I usually recommend /opt/<project-name>/<version-number> since it allows me to keep better track of what I have installed and have multiple versions of the same libraries and tools without having to deal with collisions.
I have updated my system from snow leopard to mountain lion and had to install gmp.
First of all I have installed Xcode CommandLineTools set.
Secondly, installed Homebrew. Then with it I have done steps in this topic: https://apple.stackexchange.com/questions/38222/how-do-i-install-gcc-via-homebrew
In my last step, made changes to an xcode project as colleague Marcus Karlsson told.
It's finally working! Very big Thank You :)

Resources