Simple hello world program produces: ld: 1: Syntax error: ")" unexpected - c

#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
When I want to compile this sample code with gcc aa.c -o tt I get an error:
/usr/bin/ld: 1: Syntax error: ")" unexpected
collect2: error: ld returned 2 exit status
I got this error when making a repo to install and I got the below error in the log file (a portion of the file).
gcc version 7.5.0 (Ubuntu 7.5.0-6ubuntu2)
configure:3674: $? = 0
configure:3663: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3674: $? = 1
configure:3663: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
configure:3674: $? = 1
configure:3694: checking whether the C compiler works
configure:3716: gcc conftest.c >&5
/usr/bin/ld: 1: Syntax error: ")" unexpected
collect2: error: ld returned 2 exit status
configure:3720: $? = 1

Related

Compiling a sample SDL2 program with gcc/cygwin on windows: undefined reference to WinMain

I browsed the whole internet and tried every solution for this, without result.
What I'm using:
Windows 10
Cygwin
gcc compiler
I'm trying to compile this simple code:
#include "SDL.h"
int main(int ac, char **av)
{
return 0;
}
This is what my makefile looks like:
hellosdl:
gcc hellosdl.c -L../SDL2-2.0.18/x86_64-w64-mingw32/lib -lSDL2main -lSDL2 -mwindows -I../SDL2-2.0.18/x86_64-w64-mingw32/include/SDL2
where -lSDL2main -lSDL2 -mwindows is the output of sdl2-config --libs, minus -lmingw32.
Output:
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/10/../../../../lib/libcygwin.a(libcmain.o): in function `main':
/usr/src/debug/cygwin-3.2.0-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
make: *** [Makefile:3: hellosdl] Error 1
What am I not understanding?

Getting a ---collect2.exe: error: ld returned 1 exit status--- while compiling a basic c code

code:
#include<stdio.h>
int main(void)
{
printf(" hello world\n");
return 0;
}
error:
C:/Program Files (x86)/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
I use a GCC compiler.

How should I compile this old code with cc

I'm trying to compile source code, that from 2001, in Ubuntu 18.04.2 LTS. But, I got the errors below and actually don't know how I have to change the compiling code. Can you help me for compiling this code?
Suggested compilation part from the program
SUGGESTED COMPILATION COMMAND LINE (FOR A DEC-ALPHA CC-COMPILER):
cc -lm -fast -tune host -arch host -assume whole_program \
-o mol_volume mol_volume.c
When I tried this code, errors;
cc: error: host: No such file or directory
cc: error: host: No such file or directory
cc: error: whole_program: No such file or directory
cc: error: unrecognized command line option ‘-fast’; did you mean ‘-Ofast’?
cc: error: unrecognized command line option ‘-tune’; did you mean ‘-mtune=’?
cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
cc: error: unrecognized command line option ‘-assume’; did you mean ‘-msse’?
Then, I changed -fast, -tune, -arch, -assume flags with -Ofast, -mtune=native, -march=native, -msse then add the path the for the directory part of the errors.
cc -lm -Ofast -mtune=native -march=native -msse /mypath/ -o mol_volume mol_volume.c
Then, I got that error;
mol_volume.c: In function ‘main’:
mol_volume.c:235:10: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
while( gets(s) ) {
^~~~
fgets
mol_volume.c:311:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
printf("WARNING: the %i-th atom of the pdb file %s has an unknown chemical type %s.\n",
~^
%li
i+1, pdb_name, atom_type);
~~~
/usr/bin/ld: cannot find .: File format not recognized
collect2: error: ld returned 1 exit status
You can access the source code via this link;
Source Code
My PC info:
Operation System: Ubuntu 18.04.2 LTS
Kernel ver.: 4.15.0-50-generic
GCC ver.: 7.4.0
gets was removed in C11. Compile with gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm.
It will work but you should fix the code to remove all the warnings.

Using nan() on solaris-sparc

#include <math.h>
int main() {
nan("");
}
The above code works on Linux with gcc fn.c -lm. It doesn't on solaris-sparc. How do I fix this?
The error message is:
Undefined symbol nan, first referenced in file /var/tmp//ccsdneUZ.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status.

compilation error on Executing embedded lua in C file

I am using Cygwin environment with Lua Interpreter package included while cygwin installation.
So I am able to compile and run sample lua progs.
But when i try to execute a sample c file which has lua calls , i am always getting this following error.
$ cc -o ../samples/ctest -Wall ../samples/ctest.c
/tmp/ccOYgLj4.o:ctest.c:(.text+0x2b): undefined reference to `_luaL_newstate'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x3d): undefined reference to `_luaL_openlibs'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x59): undefined reference to `_luaL_loadfile'
/tmp/ccOYgLj4.o:ctest.c:(.text+0x82): undefined reference to `_lua_pcall'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xb8): undefined reference to `_lua_getfield'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xd5): undefined reference to `_lua_call'
/tmp/ccOYgLj4.o:ctest.c:(.text+0xf0): undefined reference to `_lua_close'
collect2: ld returned 1 exit status
My sample ctest.c file contents:
#include <stdio.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/* lua interpreter */
lua_State* l;
int main () {
int dofile;
/* initialize lua */
l = lua_open();
/* load lua libraries */
luaL_openlibs(l);
/* run the hello.lua script */
dofile = luaL_dofile(l, "hello.lua");
if (dofile == 0) {
/* call foo */
lua_getglobal(l,"foo");
lua_call(l,0,0);
}
else {
printf("Error, unable to run hello.lua\n");
}
/* cleanup Lua */
lua_close(l);
return 0;
}
hello.lua file contents:
print("from c hurray")
on searching the net everywhere they say some linker error and have to include -llua51. So i tried the following .
$ cc -o ../samples/ctest -Wall -llua5.1 ../samples/ctest.c
/tmp/cc3v5Nim.o:ctest.c:(.text+0x2b): undefined reference to `_luaL_newstate'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x3d): undefined reference to `_luaL_openlibs'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x59): undefined reference to `_luaL_loadfile'
/tmp/cc3v5Nim.o:ctest.c:(.text+0x82): undefined reference to `_lua_pcall'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xb8): undefined reference to `_lua_getfield'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xd5): undefined reference to `_lua_call'
/tmp/cc3v5Nim.o:ctest.c:(.text+0xf0): undefined reference to `_lua_close'
collect2: ld returned 1 exit status
Vedhashree#Vedhashree-PC /cygdrive/c/cygwin/bin
$ ls /usr/lib/liblua*.a
/usr/lib/liblua.a /usr/lib/liblua5.1.a
/usr/lib/liblua.dll.a /usr/lib/liblua5.1.dll.a
Can you help me fix this issue and make my first embedded lua c program work?
Update:
$ cc -o ctesing -Wall ctesting.c -llua5.1
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua5.1
collect2: ld returned 1 exit status
-----------------------------------------------------------------
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua51
collect2: ld returned 1 exit status
-----------------------------------------------------------------
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua51
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llua
collect2: ld returned 1 exit status
-----------------------------------------------------------------
Still I get only these errors :(
Place -llua5.1 after ../samples/ctest.c. Objects should be linked in reverse order of dependency.
cc -o ../samples/ctest -Wall ../samples/ctest.c -llua5.1
UPDATE: Your update describes a different problem. In this case the linker cannot find a liblua5.1.a file in its search path. Make sure that you have such a library on your system and try adding its path using the -L option.

Resources