compiling OpenGL program in cygwin fails - opengl

I'm trying to compile an opengl C program. I'm on a windows platform and I use cygwin. The program is compiled using the following command.
gcc -o parallel test.c -std=c99 -lglut -lGL -lm
I have the following packages installed in my cygwin.
But when I try to compile the application I get the following errors.
$ gcc -o parallel test.c -std=c99 -lglut -lGL -lm
In file included from /usr/include/GL/freeglut_std.h:144,
from /usr/include/GL/glut.h:17,
from test.c:37:
/usr/include/w32api/GL/glu.h:68:78: error: expected ‘)’ before ‘*’ token
68 | void APIENTRY gluQuadricCallback(GLUquadric *qobj,GLenum which,void (CALLBACK *fn)());
| ^~
| )
/usr/include/w32api/GL/glu.h:78:78: error: expected ‘)’ before ‘*’ token
78 | void APIENTRY gluTessCallback(GLUtesselator *tess,GLenum which,void (CALLBACK *fn)());
| ^~
| )
/usr/include/w32api/GL/glu.h:94:74: error: expected ‘)’ before ‘*’ token
94 | void APIENTRY gluNurbsCallback(GLUnurbs *nobj,GLenum which,void (CALLBACK *fn)());
| ^~
| )
/usr/include/w32api/GL/glu.h:96:23: error: expected ‘)’ before ‘*’ token
96 | typedef void (CALLBACK *GLUquadricErrorProc)(GLenum);
I had another error prior to this, which was
$ gcc -o parallel test.c -std=c99 -lglut -lGL -lm
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
I attempted to fix this by installing libGL-devel, but that resulted in first error. I've been looking for a possible solution and most of them are outdated.
Here is what the include part looks like in the code we were given.
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h> // printf
#include <math.h> // INFINITY
#include <stdlib.h>
#include <string.h>
// Window handling includes
#ifndef __APPLE__
#include <GL/gl.h>
#include <GL/glut.h>
#else
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif

install libGLU-devel
$ cygcheck -f /usr/include/GL/glu.h
libGLU-devel-9.0.1-1
without that the compiler is using instead
/usr/include/w32api/GL/glu.h that belongs to
$ cygcheck -f /usr/include/w32api/GL/glu.h
w32api-headers-8.0.0-1
as the include search order is
$ gcc -xc -E -v -
...
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-cygwin/10/include
/usr/local/include
/usr/include
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../lib/../include/w32api
End of search list.
and the last one is usr/include/w32api

Related

With MinGW g++ 9.2.0 I get an error: 'mutex' is not a member of 'std'

I updated my g++ because my older version didn't fully support std::filesystem, but now I cannot use mutexes at all. Example code:
#include <mutex>
int main(const int argc, const char** argv)
{
std::mutex test;
return 0;
}
Compiled with:
g++ -Wall -pedantic main.cpp -std=c++17 -o main.exe
The error, note how it suggests adding include for <mutex> right under the include that is already there:
main.cpp: In function 'int main(int, const char**)':
main.cpp:5:8: error: 'mutex' is not a member of 'std'
5 | std::mutex test;
| ^~~~~
main.cpp:2:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
1 | #include <mutex>
+++ |+#include <mutex>
2 |
The full version of g++ is: g++ (MinGW.org GCC Build-2) 9.2.0. I installed MinGW using the MinGW installation manager. Is it possible that I am missing the correct version of stdlib?
I opened the mutex file in the MinGW directory and I see nothing that would be obviously wrong.

What should i have on windows to use std::mutex?

I‘m getting error on Windows 10 64-bits when trying to use the C++ std::mutex. The code was basically written for Linux but I'm trying to port it to Windows. (You can see compiler line in the error message that I added below.)
This is my code:
#ifndef UNTITLED_LIBRARY_H
#define UNTITLED_LIBRARY_H
#include <sys/types.h>
#include <Winsock2.h>
#include <mutex>
#include <thread>
class TCPServer
{
static std::mutex mt;
};
#endif //UNTITLED_LIBRARY_H
Here is the error message:
g++ -Wall -std=c++14 -I./ library.h -o libSimpleNetwork.so -fPIC -shared
library.h:11:17: error: 'mutex' in namespace 'std' does not name a type
11 | static std::mutex mt;
| ^~~~~
library.h:8:1: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
7 | #include <thread>
+++ |+#include <mutex>
8 |
So the answer to this issue is to install mingw64 (not mingw32!): https://sourceforge.net/projects/mingw-w64/
This includes the posix x86_64-posix-seh that gcc needs for libstd

'<some system header>: error: ‘<insert function here>’ is not a member of ‘std’ ' after moving source file

Right after moving a source-file from my project to a subdirectory, gcc spit out a weird error (it did compile perfectly fine before)
make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
CXX main.o
In file included from /usr/include/c++/9/bits/stl_algobase.h:69,
from /usr/include/c++/9/memory:62,
from /usr/include/c++/9/memory_resource:37,
from main.h:5,
from main.cpp:1:
./debug/debug.h:14:28: error: variable or field ‘debug_queue_addN’ declared void
14 | void debug_queue_addN(std::string msg);
| ^~~~~~
compilation terminated due to -Wfatal-errors.
I did managed to 'resolve' that problem by including < string > in said header file, however a new, even weirder error appeared.
make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
CXX main.o
In file included from /usr/include/c++/9/bits/stl_algobase.h:69,
from /usr/include/c++/9/memory:62,
from /usr/include/c++/9/memory_resource:37,
from main.h:5,
from main.cpp:1:
./debug/debug.h:14:28: error: variable or field ‘debug_queue_addN’ declared void
14 | void debug_queue_addN(std::string msg);
| ^~~~~~
compilation terminated due to -Wfatal-errors.
At this point I even tried including < algorithm > before any other inclusion anywhere else, but it didn't help at all. Instead it threw out this even weirder error...
make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
CXX main.o
In file included from /usr/include/c++/9/bits/basic_string.h:48,
from /usr/include/c++/9/string:55,
from ./debug/debug.h:4,
from /usr/include/c++/9/bits/stl_algobase.h:69,
from /usr/include/c++/9/bits/char_traits.h:39,
from /usr/include/c++/9/ios:40,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from main.cpp:2:
/usr/include/c++/9/string_view: In member function ‘std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::copy(_CharT*, std::basic_string_view<_CharT, _Traits>::size_type, std::basic_string_view<_CharT, _Traits>::size_type) const’:
/usr/include/c++/9/string_view:260:32: error: ‘min’ is not a member of ‘std’; did you mean ‘minus’?
260 | const size_type __rlen = std::min(__n, _M_len - __pos);
| ^~~
| minus
compilation terminated due to -Wfatal-errors.
Now, does anybody have an idea why this happens/ what I can do to fix this?
Also, here's the in the error output mentioned code.
main.cpp
#include "main.h"
#include "server.h"
#include "config.h"
#include "debug/debug.h"
#include "pidfile.h"
#include "messages.h"
#include <cstring>
#include <iostream>
#include <thread>
#include <algorithm>
[CUT HERE]
main.h
#ifndef __MAIN_H___
#define __MAIN_H___
#define __cpp_transactional_memory 0
#include <memory_resource>
extern std::pmr::synchronized_pool_resource* _upstream_resource;
extern std::pmr::pool_options _general_pool_options;
#endif
debug/debug.h
#ifndef __DEBUG_H__
#define __DEBUG_H__ 1
#include <string> // I added this as a 'solution' to the first mentioned problem
#include "config.h"
#ifdef DEBUGBUILD
#define dbg_out(a) debug_queue_addN(a)
#define dbg_sout(func, msg) this->debug_queue_add(func, msg)
#define dbg_csout(inh, func, msg) debug_queue_addI(inh, func, msg)
#define fatal_err_out(a) std::cout << a
void debug_print();
void debug_queue_addN(std::string msg);
void debug_queue_addI(std::string inh, std::string func, std::string msg);
#else
#define dbg_out(a)
#define dbg_sout(func, msg)
#define dbg_csout(inh, func, msg)
#define fatal_err_out(a) std::cerr << a
#endif
#endif
and finally Makefile.am
SUBDIRS =
EXTRA_DIST =
bin_PROGRAMS =
#check_PROGRAMS =
#TESTS =
GENERAL_GCC_FLAGS = -std=gnu++17 \
-Og -falign-functions \
-falign-jumps -falign-labels \
-falign-loops -fwrapv \
-fbranch-target-load-optimize \
-fasynchronous-unwind-tables \
-fcode-hoisting -fdce -fdse \
-fgcse -fhoist-adjacent-loads \
-fipa-icf -fipa-cp -fipa-pta -fipa-vrp \
-fplt -fpeephole -freorder-functions \
-fstack-protector-all -m80387 -mhard-float \
-malign-double -mcld -mcx16 -msahf -mmovbe -mcrc32 \
-mrecip -mprefer-avx128 -mmmx -msse4.2 -mavx512vbmi \
-msha -maes -mrdrnd -mf16c -pthread -mpc80 -m64 -g3 -fconcepts \
[CUT OUT a whole lot of -Wxxxxx]
# --param asan-stack=1 --param asan-instrument-allocas=1 \
# --param asan-globals=1 --param asan-instrument-writes=1 \
# --param asan-instrument-reads=1 --param asan-memintrin=1 \
# --param asan-use-after-return=1 --param asan-instrumentation-with-call-threshold=1 \
# -fsanitize=address
GENERAL_FLAGS = $(GENERAL_GCC_FLAGS)
AM_CFLAGS = $(WARNCFLAGS) $(GENERAL_FLAGS)
AM_CXXFLAGS = $(WARNCXXFLAGS) $(CXX1XCXXFLAGS) $(GENERAL_FLAGS)
AM_CPPFLAGS = $(GENERAL_FLAGS)
LDADD = #LIBXML2_LIBS# \
#LIBEV_LIBS# \
#OPENSSL_LIBS# \
#SYSTEMD_LIBS# \
#JANSSON_LIBS# \
#ZLIB_LIBS# \
#APPLDFLAGS#
bin_PROGRAMS += server_app
server_class_packetEx_SOURCES = packets/dcs_do.cpp packets/hbp_do.cpp packets/ack_do.cpp
server_class_SOURCES = server.cpp perform_commands.cpp handle_commands.cpp server_message_byte_strs.cpp \
networking.cpp messages.cpp packet_check.cpp send_packages.cpp errors.cpp $(server_class_packetEx_SOURCES)
auth_class_SOURCES = auth/authentication.cpp
debug_SOURCES = debug/debug.cpp
server_app_SOURCES = main.cpp export.cpp pidfile.cpp $(server_class_SOURCES) $(auth_class_SOURCES)
if DEBUGBUILD
server_app_SOURCES += $(debug_SOURCES)
endif
From the errors, it seems that your debug/debug.h is being picked up by /usr/include/c++/9/bits/stl_algobase.h. This conflicts with the actual /usr/include/c++/9/debug/debug.h.
On my system at least, these includes are done using the #include <...> form, ie by searching the system include path. It looks like you added compilation flags that put your code also on that path. Something as innocent as -I., perhaps?
To solve this problem you should either get rid of the extra -I flag or rename your debug/debug.h file.

error: stray ‘\224’ in program after including external library

I'm new to C++. I'm trying to use the libserial
bitmap_test.cpp
#include <SerialStream.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace LibSerial ;
int main()
{
SerialStream serial_port( "/dev/ttyS0" ) ;
return 0;
}
The error:
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:520: error: null character(s) ignored [-Werror]
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:1: error: stray ‘\17’ in program
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:525: error: null character(s) ignored [-Werror]
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:1: error: stray ‘\231’ in program
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:529: error: null character(s) ignored [-Werror]
/usr/local/lib/libserial.a:118:532: error: null character(s) ignored [-Werror]
In file included from <command-line>:0:0:
/usr/local/lib/libserial.a:118:1: error: stray ‘\10’ in program
/usr/local/lib/libserial.a:118:1: error: stray ‘\34’ in program
...
The makefile
COMPILER = -c++
OPTIONS = -ansi -pedantic-errors -Wall -Wall -Werror -Wextra -o
LINKER_OPT = -L/usr/lib -lserial -include/usr/local/lib/libserial.a -lstdc++ -lm
all: bitmap_test
bitmap_test: bitmap_test.cpp bitmap_image.hpp
$(COMPILER) $(OPTIONS) bitmap_test bitmap_test.cpp $(LINKER_OPT)
I did research and understand it's a problem with encoding but don't know how to fix it.
Any help is much appreciated.
EDIT:
The library is in the right path:
/sbin/ldconfig -p | grep libserial
libserial.so.0 (libc6,x86-64) => /usr/local/lib/libserial.so.0
libserial.so.0 (libc6,x86-64) => /usr/lib/libserial.so.0
libserial.so (libc6,x86-64) => /usr/local/lib/libserial.so
libserial.so (libc6,x86-64) => /usr/lib/libserial.so
But if I change the Makefile as suggested, I will have this problem:
c++ -ansi -pedantic-errors -Wall -Wall -Werror -Wextra -o bitmap_test bitmap_test.cpp -L/usr/local/lib -lstdc++ -lm -lserial
bitmap_test.cpp: In function ‘int main()’:
bitmap_test.cpp:32:40: error: call of overloaded ‘SerialStream(const char [11])’ is ambiguous
SerialStream serial_port( "/dev/ttyS0" ) ;
^
bitmap_test.cpp:32:40: note: candidates are:
In file included from bitmap_test.cpp:19:0:
/usr/local/include/SerialStream.h:98:13: note: LibSerial::SerialStream::SerialStream(std::string, LibSerial::SerialStreamBuf::BaudRateEnum, LibSerial::SerialStreamBuf::CharSizeEnum, LibSerial::SerialStreamBuf::ParityEnum, short int, LibSerial::SerialStreamBuf::FlowControlEnum)
SerialStream( const std::string fileName,
^
/usr/local/include/SerialStream.h:84:22: note: LibSerial::SerialStream::SerialStream(std::string, std::ios_base::openmode)
explicit SerialStream( const std::string fileName,
^
make: [bitmap_test] Error 1 (ignored)
Stray characters usually has to do with the source encoding.
The “null character(s) ignored” diagnostic would generally indicate that the source code is UTF-16 or UTF-32.
However, the makefile shows that you're treating a static library as a forced include file:
-include/usr/local/lib/libserial.a
With my g++ in Windows:
> g++ -v --help 2>&1 | find "-include "
--include This switch lacks documentation
-include <file> Include the contents of <file> before other

SWIG - Problem with namespaces

I'm having trouble getting the following simple example to work with SWIG 1.3.40 (and I also tried 1.3.31). The Foo structure comes through as a Python module as long as I don't wrap it in a namespace, but as soon as I do I get a compilation error in the generated test_wrap.c.
test.h:
#ifndef __TEST_H__
#define __TEST_H__
#define USE_NS 1
#if USE_NS
namespace ns {
#endif
struct Foo {
float a;
float b;
float func();
};
#if USE_NS
}
#endif
#endif
test.cpp
#include "test.h"
#if USE_NS
namespace ns {
#endif
float Foo::func()
{
return a;
}
#if USE_NS
}
#endif
test.i
%module test
%{
#include "test.h"
%}
%include "test.h"
I run the following commands for building a bundle on OSX 10.6.3:
swig -python test.i
g++ -c -m64 -fPIC test.cpp
g++ -c -m64 -fPIC -I/usr/local/include -I/opt/local/include -I/opt/local/Library/Frameworks/Python.framework/Headers test_wrap.c
g++ -o _test.so -bundle -flat_namespace -undefined suppress test_wrap.o test.o -L/usr/local/lib -L/opt/local/lib -lpython2.6
This works, but only if I take out the namespace. I though SWIG handled namespaces automatically in simple cases like this. What am I doing wrong?
This is the error that I get - it looks like SWIG references a 'ns' and a 'namespace' symbol which are undefined.
test_wrap.c: In function ‘int Swig_var_ns_set(PyObject*)’:
test_wrap.c:2721: error: expected primary-expression before ‘=’ token
test_wrap.c:2721: error: expected primary-expression before ‘namespace’
test_wrap.c:2721: error: expected `)' before ‘namespace’
test_wrap.c:2721: error: expected `)' before ‘;’ token
test_wrap.c: In function ‘PyObject* Swig_var_ns_get()’:
test_wrap.c:2733: error: expected primary-expression before ‘void’
test_wrap.c:2733: error: expected `)' before ‘void’
In your test.i file, add a "using namespace ns" line after the #include. Without that, your swig wrapper code won't know to look for Foo in the "ns" namespace.