Eclipse CDT errors when building files - c

When trying to build a simple Hello world program in C and Elcipse, I get the following errors:
make: *** [C.exe] Error 1 C C/C++ Problem
recipe for target 'C.exe' failed makefile /C/Debug line 29 C/C++ Problem
undefined reference to `WinMain' C line 39, external location: C:\cygwin64\usr\src\debug\cygwin-1.7.33-1\winsup\cygwin\lib\libcmain.c C/C++ Problem
I'm using Cygwin. How can I fix this? I am selected the Cygwin toolchain, and I have the PATH set to C:\cygwin64\bin.

The undefined reference means you are missing a library. To set this up right click the project, select Properties -> C/C++ General -> Paths and Symbols -> Libraries and Libraries Paths. Add the appropriate library and build again.
Also look here - gcc-undefined-reference-to and here.

Related

Setting up the `regex.h` library on Windows with VS Code

I've been trying to get the regex.h library to work all day, but it's not working. (Here are my VS Code workspace configurations: https://github.com/EnderCommunity/Murmur/tree/main/.vscode - all the compiler info are here)
This is the file that I was trying to get the regex library to work with:
https://github.com/EnderCommunity/Murmur/blob/main/compiler/libraries/regex/reg.h
I tried to include the library normally, but it returns an error:
And I tried to include this library, but it returns some compiling errors:
> Executing task: C/C++: gcc.exe build active file <
Starting build...
"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe" -g C:\Users\adels\Desktop\EnderCommunity\Projects\Murmur\compiler\start.c -o C:\Users\adels\Desktop\EnderCommunity\Projects\Murmur\compiler\start.exe
C:\Users\adels\AppData\Local\Temp\ccifSq1r.o: In function `regChk':
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:15: undefined reference to `__imp_regcomp'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:22: undefined reference to `__imp_regexec'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:33: undefined reference to `__imp_regerror'
C:/Users/adels/Desktop/EnderCommunity/Projects/Murmur/compiler/libraries/regex/reg.h:40: undefined reference to `__imp_regfree'
collect2.exe: error: ld returned 1 exit status
Build finished with error(s).
The terminal process terminated with exit code: -1.
Terminal will be reused by tasks, press any key to close it.
So the way that I included this library might be wrong! What am I doing wrong here?
Using MSYS2 will fix this, it comes with all the necessary libraries for C.

Undefined reference while calling GUROBI in C, Codeblocks

I downloaded Codeblocks to call GUROBI - an optimization package with libraries- from C. While building the example C code from GUROBI (See here), I get 15 errors in the form of:
.../main.c:32: undefined reference to `GRBloadenv#8'
.../main.c:32: undefined reference to `GRBreadmodel#12'
I already did the following:
In global compiler settings
Set Settings>Compiler>Search Directories>Compiler path to GUROBI's include folder (with .h files)
Set Search Directories>Linker path to GUROBI's lib folder (with .lib files)
Link libraries from Linker settings.
Did the same three steps above for the prject itself, i.e. Project>Build Options>...[same as Step 1]
Having spent the whole day, i cant find any solution. Any help is highly appreciated.
I'm working on Windows 10, Code::Blocks 17.12, and Gurobi 8.1.0

Mingw and Eclipse unable to find library - 2

I am faced with the exact same situation as the question raised by Gustavo in the following Link. Also, I have tried all the solutions posted in that link and other tags (such as changing library names from opus.a to libopus.a, change '\' to '/' and so on) but none of these have solved my problem. By opening the properties of the library file, these are the following things displayed:
Path: /demo/opusfile/libopusfile.a
Type: File (Static Library)
Location: U:\data\Jag\eclipse\wrksp\demo\opusfile\libopusfile.a
The error message displayed by Mingw is as follows:
15:56:57 **** Incremental Build of configuration Debug for project demo ****
Info: Internal Builder is used for build
gcc -o demo.exe "src\\demo.o" -lU:/data/Jag/eclipse/wrksp/demo/opusfile/libopusfile.a
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lU:/data/Jag/eclipse/wrksp/demo/opusfile/libopusfile.a
collect2.exe: error: ld returned 1 exit status
collect2.exe: error: ld returned 1 exit status
Could someone please let me know what am I missing ? I am not able to resolve this issue
I think I found the solution, thanks to the answer posted in this Link. So basically to summarize the solution, I had to remove the 'lib' prefix, the '.a' suffix and the library path when I specified the libraries (-l parameters). The library path has to be specified in the -L parameter . This resolved the above problem but led to another hurdle by Mingw:
libopusfile.dll.a: could not read symbols: Archive has no index; run ranlib to add one.
I executed the 'ranlib' command in the command prompt
cmd_path> ranlib libopusfile.dll.a
, as suggested by the compiler, and this solved all my issues!

Build error with a Hello World C program with a default CDT plugin installation in Eclipse on Ubuntu

I just installed the CDT plugin for Eclipse on my Ubuntu machine. I made a new Hello World ANSI C Project and put the code for a basic C program inside the source file:
#include <stdio.h>
int main(void)
{
printf("Hello World\n");
return 0;
}
When I go to build the program, I get the error that "Errors occurred during the build.
Errors running builder 'CDT Builder' on project 'CS47 HW2'.
Illegal character in path at index 4: CS47 HW2"
Furthermore, 2 errors occur when I go to build the program in the Problems window, along with 85 warnings. The two errors are:
Description Resource Path Location Type
./src/CS47 HW2.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC CS47 HW2 C/C++ Problem
and
Description Resource Path Location Type
make: * [libCS47 HW2] Error 1 CS47 HW2 C/C++ Problem
First comment nailed it. For some reason Eclipse would allow a space in the project name with the CDT plugin.

Do I need an "so" file or what's wrong?

(I'm on Windows.)
I try to build pysox. Therefore I built libsox (part of SoX). It is said, that pysox needs "libsox.so and libsox.a in your link path." When building libsox I got "libsox.a", "libsox-1.dll", "libsox.dll.a", "libsox.la", "libsox.lai" and many other strange files. When I placed "libsox.a" in my link path, the previously shown error disappeared. But now the build script has an error when it calls mingw32-gcc which says:
C:\Programme\MinGW\bin\mingw32-gcc.exe -shared -s build\temp.win32-2.7\Release\pysox\sox.o build\temp.win32-2.7\Release\pysox\sox.def -LC:\Programme\Python\libs -LC:\Programme\Python\PCbuild -lsox -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pysox\sox.pyd
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x3a96): undefined reference to `sox_get_encodings_info'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x5035): undefined reference to `sox_get_encodings_info'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x795d): undefined reference to `bcopy'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0xa8b3): undefined reference to `bcopy'
collect2: ld returned 1 exit status
error: command 'mingw32-gcc' failed with exit status 1
The following attempts didn't work:
Placing "libsox-1.dll" in link path
Renaming it to "libsox.dll"
Renaming it to "libsox.so"
Placing all files generated along with "libsox.a" in link path
Do I really need an "so" file on Windows (how do I get it)? Or what has to be changed?
MinGW uses a static interface library for each dynamic link library (DLL). The libsox.dll.a library is the one you need at link time, i.e. that needs to be copied into the link path. libsox-1.dll is required in the PATH at runtime, but not needed at link time.
You don't need a .so file on Windows platforms. It seems that some symbols are missing from the static library libsox.a, or that a library is missing from the link line. Windows platforms do not allow unresolved symbols in DLLs, contrary to UNIX-like .so platforms. You might have to give the library containing sox_get_encodings_info and friends explicitly on the command line, remembering precedence on the linker line.

Resources