OracleSolaris 11.2 -- simple file I/O, cc warning - file-io

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd;
fd = open("abc.txt", O_RDONLY);
if (fd < 0)
{
exit(EXIT_FAILURE);
}
printf("fd %d\n", fd);
close(fd);
exit(EXIT_SUCCESS);
}
Now I build it:
$ cc -errwarn=%all -o ~/tmp/aa ~/tmp/a.c
warning: bad message tag: /export/home/rmashak/tmp/a.call
$ cc -V
cc: Sun C 5.12 SunOS_i386 2011/11/16
It does execute fine, but what's the warning all about?

I have insufficient reputation to add a comment... This does look like a compiler bug with the parser. Compiling with later version of cc does not produce this error.
$ cc -V
cc: Sun C 5.13 SunOS_i386 2014/10/20
$ cc -errwarn=%all -o ~/tmp/aa ~/tmp/a.c
$
In your output cc appears to have presented the source filename concatenated with the remainder of '-errwarn' tag 'all', odd!

The error means that you have passed an unrecognized option to -errwarn:
% cc -errwarn=%mumblefrotz -o hello hello.c
warning: bad message tag: %mumblefrotz
It appears your shell somehow converted the % in your command into /export/home/rmashak/tmp/a.c before passing it to the compiler. It looks like some shells such as zsh may expand % signs specially in command processing - check the docs for whichever shell you use.
If you're using recent versions of Solaris Studio, the % is optional to avoid problems like this - you can change your command instead to be:
cc -errwarn=all -o ~/tmp/aa ~/tmp/a.c

Related

How did Cygwin g++ resolve it?

I am puzzled how a mere g++ -o testpoco testpoco.cpp -lPocoFoundation was able to compile successfully in my Cygwin environment. The complete C++ code is below:
#include <Poco/File.h>
int main (int argc, char *argv[])
{
Poco::File f("/tmp/test.log");
if (f.exists()) {
return 1;
}
return 0;
}
I installed the cygwin Poco development headers and libraries and I verified they are in:
/usr/include/Poco/ (the header files)
/usr/lib/ (the libraries)
But without specifying those include and library path in g++ how did it was able to compile and produce the exe? I checked the output of g++ -v and did not see any routes to Poco.
The compiler has default search paths for include files and for libraries. (Actually the latter applies to the linker, not the compiler, but the g++ command invokes both.)
/usr/include and /usr/lib are in those default search paths.
You specified #include <Poco/File.h>, so the compiler found /usr/include/Poco/File.h.
You specified -lPocoFoundation, so the linker found /usr/lib/libPocoFoundation.dll.a, the file that contains the code implementing the PocoFoundation library under Cygwin.
I checked the output of g++ -v and did not see any routes to Poco
The command g++ -v will just print out some version information about GCC, and how it was configured. Adding the -v option to your real commands used for compiling and/or linking will show the search paths for headers and libraries.
In other words, instead of just g++ -v you should try:
g++ -o testpoco testpoco.cpp -lPocoFoundation -v
This will show the search paths that Keith Thompson refers to in his answer.

IBM AIX 7.1 unable to compile with gtk2-2.24.30-2

I have tried to install GTK2 on my IBM AIX7.1 from AIX Toolbox for Linux Applications. It offers me gtk2-2.24.30-2waixX11 so I have intalled it via rpm -i.
Now I have just simple empty main.c which only includes GTK2.
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
return 0;
}
When I try to compile my example, using:
gcc -maix64 main.c `pkg-config --cflags gtk+-2.0`
It returns me an error:
In file included from /usr/include/sys/thread.h:41:0,
from /usr/include/sys/ptrace.h:28,
from /usr/include/sys/proc.h:42,
from /usr/include/sys/pri.h:43,
from /usr/include/sys/sched.h:38,
from /usr/include/sched.h:51,
from /usr/include/pthread.h:63,
from /home/run/tools/include/glib-2.0/glib/deprecated/gthread.h:128,
from /home/run/tools/include/glib-2.0/glib.h:108,
from /home/run/tools/include/glib-2.0/gobject/gbinding.h:28,
from /home/run/tools/include/glib-2.0/glib-object.h:23,
from /home/run/tools/include/glib-2.0/gio/gioenums.h:28,
from /home/run/tools/include/glib-2.0/gio/giotypes.h:28,
from /home/run/tools/include/glib-2.0/gio/gio.h:26,
from /home/run/tools/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /home/run/tools/include/gtk-2.0/gdk/gdk.h:32,
from /home/run/tools/include/gtk-2.0/gtk/gtk.h:32,
from main.c:1:
/home/run/tools/include/gtk-2.0/gtk/gtktypeutils.h:61:24: error: expected ';', ',' or ')' before '.' token
gpointer func_data);
^
/home/run/tools/include/gtk-2.0/gtk/gtkwindow.h:443:36: error: expected ';', ',' or ')' before '.' token
gpointer func_data);
It continues with the same error over more header. It seems that gpointer is unknown for GTK headers? I even have tried to add glib include into gtktypeutils.h, typedef void* gpointer definition into the same file or I have chaged gpointer to void*. Bus it returns always the same problem.
Here are my glib and gtk packages:
rpm -qa | grep gtk
gtk2-2.24.30-2waixX11
gtk2-devel-2.24.30-2waixX11
rpm -qa | grep glib
glib2-2.56.1-2
glib2-devel-2.56.1-2
Do you heve some idea? Thanks, Jiri.
In AIX, symbol func_data is also defined in /usr/include/sys/timer.h as t_union.data unless you define symbol _LINUX_SOURCE_COMPAT (I cannot tell what other consequences this definition might have):
gcc -maix64 main.c -D_LINUX_SOURCE_COMPAT `pkg-config --cflags gtk+-2.0`
Or rather, you could edit the header files in question, something like this:
perl -pi.bak -e 's/func_data/pfunc_data/g' \
$(grep -l func_data $(find pathto/gtk/ -name '*.h'))

Link FLTK with g++

In order to try out FLTK, I have the following file structure:
project
|--main.cc
|--include
| |--FL
| | |--all FLTK header files
|--lib
| |--libfltk.a
| |--other fltk libraries
With the following content in main.cc:
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main()
{
Fl_Window window(200, 200, "Window title");
Fl_Box box(0,0,200,200,"Hello, World!");
window.show();
return Fl::run();
}
Now when I run:
g++ -std=c++11 -c -o main.o main.cc -I include
g++ -std=c++11 -o main.exe main.o -L lib -lfltk
I get a whole bunch of errors after the second call to g++:
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0xf3): undefined reference to `CreateDIBSection#24'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x1cf): undefined reference to `DeleteObject#4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x258): undefined reference to `CreateBitmap#20'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2a6): undefined reference to `DeleteObject#4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2b1): undefined reference to `DeleteObject#4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x5b): undefined reference to `OleUninitialize#0'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x83): undefined reference to `RestoreDC#8'
etc ...
The result is the same when I try to link the other FLTK libraries. Can anyone help me with that?
I use gcc from Windows, with MingW.
To solve this sort of problems is necessary to take help from fltk-config script. Therefore, it is enought to add line fltk-config --ldflags to compiler to avoid linker errors. Be sure to use "`" symbol around this command since this is the script and its should be executed.

Change Glib with CMake

The Problem:
So, I'm writing an application in C that uses the glib's hash table function. Unfortunately, because Homebrew installs glib into a subdirectory, pre-written includes are broken, and it completely fails to compile. Part of the problem is related to the tendency glib has to hide itself, but I'm aware of how to solve this, and have written a makefile that works. However, I would still prefer to be able to use my IDE as usual, and this seems like it may cause other problems in the future, so I am wondering whether anybody has any advice.
Below is the makefile, cmakelists.txt and errors.
Please note that my problem is not including CMake, it is due to the fact that Homebrew has installed it to /usr/lib/local/glib-2.0/glib.h, and the header files it includes are under /usr/lib/local/glib-2.0/glib/. Unfortunately, all of glibs header include the others as such
#include <glib/galloca.h>
#include <glib/garray.h>
#include <glib/gasyncqueue.h>
#include <glib/gatomic.h>
#include <glib/[...]>
where these should be
#include <glib-2.0/glib/galloca.h>
#include <glib-2.0/glib/garray.h>
e.t.c, You get the idea
Makefile
# Compiler
CC = gcc
#CFlags
CFlags = -g -Wall -I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include -L/usr/local/Cellar/glib/2.46.2/lib -L/usr/local/opt/gettext/lib -lglib-2.0 -lintl -D_REENTRANT -I/usr/local/Cellar/gtk+3/3.18.9/include/gtk-3.0 -I/usr/local/Cellar/glib/2.46.2/include/gio-unix-2.0/ -I/usr/local/Cellar/cairo/1.14.6_1/include/cairo -I/usr/local/Cellar/libepoxy/1.3.1/include -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/harfbuzz/1.2.4/include/harfbuzz -I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 -I/usr/local/Cellar/atk/2.18.0_1/include/atk-1.0 -I/usr/local/Cellar/cairo/1.14.6_1/include/cairo -I/usr/local/Cellar/pixman/0.34.0/include/pixman-1 -I/usr/local/Cellar/fontconfig/2.11.1_2/include -I/usr/local/Cellar/freetype/2.6.3/include/freetype2 -I/usr/local/Cellar/libpng/1.6.21/include/libpng16 -I/usr/local/Cellar/gdk-pixbuf/2.32.3/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/libpng/1.6.21/include/libpng16 -I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 -I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include -I/usr/local/opt/gettext/include
TARGET = main
all: $(TARGET)
$(TARGET): $(TARGET).c
$(CC) $(CFlags) -o $(TARGET) $(TARGET).c
clean:
$(RM) $(TARGET)
Compile Errors
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/ennis/Library/Caches/CLion12/cmake/generated/85d4a0ab/85d4a0ab/Debug --target all -- -j 4
[ 50%] Building C object CMakeFiles/TaskAppBuilder_C.dir/main.c.o
In file included from /Users/ennis/TaskAppBuilder-C/main.c:4:
In file included from /Users/ennis/TaskAppBuilder-C/main.h:15:
In file included from /Users/ennis/TaskAppBuilder-C/glib.h:30:
/usr/local/include/glib-2.0/glib.h/galloc.h:32:10: fatal error: 'galloc.h' file not found
#include <galloc.h>
^
1 error generated.
make[2]: *** [CMakeFiles/TaskAppBuilder_C.dir/main.c.o] Error 1
make[1]: *** [CMakeFiles/TaskAppBuilder_C.dir/all] Error 2
make: *** [all] Error 2
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(TaskAppBuilder_C)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c11")
set(SOURCE_FILES main.c main.h)
add_executable(TaskAppBuilder_C ${SOURCE_FILES} main.c main.h)

Objective C compiling with clang on Linux Foundation/Foundation.h linking: file not found

I'm trying to compile a program in Objective C on Ubuntu, I have installed GNUstep, set all the GNUSTEP_* environment variables, and installed clang, because I read that gcc can't compile Objective-C code with blocks (Objective-C 'anonymous' functions, just to be clear: ^ { }).
What I get when I run this command:
clang hello.m -o hello
Is:
hello.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
^
1 error generated.
I tried this also:
clang -L '/usr/include/GNUstep/Foundation/Foundation.h' hello.m -o hello
Where /usr/include/... is the path to the Foundation.h file on my system; but I still get the same result.
How can I link those header files automatically and compile Objective-C?
Thanks!
You can use gnustep-config:
clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` hello.m -o hello