I'm getting GCC compiling on windows with std::atomic and std::thread support.
I'm using mingw from here: http://winlibs.com/
I'm building with this command:
g++.exe #CMakeFiles/StrFormatsJSONTest.dir/includes_CXX.rsp -latomic -lglu32 -lopengl32 -D_WIN32_WINNT=0x600 -DWINVER=0x600 -D_WIN32_LEAN_AND_MEAN=1 -g -std=gnu++2a -o main.cpp.obj -c main.cpp
However, when using #include <atomic> the following error occurs:
[build] c:\utils\bin\mingw32\include\c++\10.3.0\ext\atomicity.h:83:9: error: '__gthread_active_p' was not declared in this scope
[build] 83 | if (__gthread_active_p())
If I define the function manually, I get a multiple definition error (so clearly it in the project somehow).
I'm including threads using:
find_package( Threads )
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
I'm including latomic using:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -latomic -lglu32 -lopengl32 -D_WIN32_WINNT=0x600 -DWINVER=0x600 -D_WIN32_LEAN_AND_MEAN=1 -D__GTHREADS=1")
^ Like this because I need it in ALL targets within the project.
The library states that the function should be present if GTHREADS macro is 1:
Clearly it is, thats where the error is:
When I add a definition (weakly linked) before #include <atomic> it works... But I get other errors such as:
error: '__gthread_once_t' does not name a type; did you mean '__gthread_active_p'?
For some reason GCC isn't including any one of these:
gthr-default.h
gthr-posix.h
gthr-single.h
Found the issue, I had a file called "Signal.h" it was being included instead of GCC's <signal.h>
More info, this is an issue on windows due to case insensitive filenames.
Related
I just made a program that compiles and runs perfectly in Visual Studio, and should be compatible with Android (uses no OS-Specific includes), but there is a red error squiggle in Android Studio under the C++ stl list begin and end iterator function (as well as compilation failing as a direct result of it). I have very little experience with cmake, and being that it is one of the only differences from VS, it seems a likely culprit.
cpp file:
void cellStats::removeAllMatches(int row, int col, int val)
{
std::list<layout>::iterator Layout = layoutListPointer.begin(); // Error here
while (Layout != layoutListPointer.end()) { // Error here
if (Layout->get(row, col) != val) {
layoutListPointer.erase(Layout);
}
else {
Layout++;
}
}
update();
}
header file:
public:
void cellStats::removeAllMatches(int row, int col, int val)
//More
private:
std::list<layout> layoutListPointer;
//more
CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
set (CMAKE_CXX_STANDARD 11)
include_directories(${MY_SOURCE_DIR}/src/main/cpp)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
add_library(cellStats-class SHARED src/main/cpp/cellStats.cpp)
add_library(board-class SHARED src/main/cpp/board.cpp)
add_library(cell-class SHARED src/main/cpp/cell.cpp)
add_library(layout-class SHARED src/main/cpp/layout.cpp)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
Edit: The Error Log is:
Build command failed.
Error while executing process C:\Users\Metagross\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\.externalNativeBuild\cmake\debug\x86 --target cellStats-class}
[1/2] Building CXX object CMakeFiles/cellStats-class.dir/src/main/cpp/cellStats.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libcellStats-class.so
FAILED: cmd.exe /C "cd . && C:\Users\Metagross\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android --gcc-toolchain=C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -LC:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libcellStats-class.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libcellStats-class.so CMakeFiles/cellStats-class.dir/src/main/cpp/cellStats.cpp.o -latomic -lm "C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++_static.a" "C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++abi.a" && cd ."
C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\src\main\cpp/cellStats.cpp:39: error: undefined reference to 'layout::get(int, int)'
C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\src\main\cpp/cellStats.cpp:91: error: undefined reference to 'layout::get(int, int)'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
The problem is due to how you organized your project. You have several small shared libraries that all seems to depend on each other, but you probably don't link with them as needed.
Like the cellStats-class library depends on the layout-class library (where I assume you define all the layout class functions), but you probably don't link with it.
Unless you are going to use all the different libraries separately for different programs, I suggest you don't make libraries at all. Instead add all the sources to the main target you build.
On another note, you have undefined behavior in your code.
From this std::list::erase reference:
References and iterators to the erased elements are invalidated.
That means you can no longer use the iterator Layout once you called erase. And even if you could you never advance the iterator if the condition Layout->get(row, col) != val is true.
You need to use what erase returns:
Layout = layoutListPointer.erase(Layout);
I'd like to learn how to use lapack together with C/C++ code in Windows. I am a C/C++ programming newbie, so I know how to code in C, how to organize the code in h/c files, and how to compile them with gcc under cygwin / MinWG / VS. What I'm totally new to is the use of external libraries, such as lapack.
To learn how to use it with Cygwin (64bit), I followed the procedure indicated here
(http://matrixprogramming.rudnyi.ru/2011/04/using-lapack-from-c/)
which seemed to be successful and created the built version of lapack in the folder $HOME\lapack-3.3.0
Now I want to re-run this example: main.cc
What I did was to try to compile it by calling
$ g++ -O3 main.cc -L$HOME/lapack-3.3.0 -llapack -lblas -lgfortran -I ./include -o main
and what I get is
main.cc: In function ‘int main(int, char**)’:
main.cc:39:23: error: ‘dgetf2’ was not declared in this scope
info = dgetf2(A, ipvt);
^
main.cc:45:23: error: ‘dgetrf’ was not declared in this scope
info = dgetrf(A, ipvt);
^
main.cc:55:26: error: ‘dgetrs’ was not declared in this scope
info = dgetrs(A, B, ipvt);
^
where the "include" folder only contains the
Matrix.h
matrix class required in main.cc
To me it seems that some header files are missing. What I do not understand is how this is possible if the building process of the libraries was successful. Do I have to give further "-I options"? I looked for "dgetf2", "dgetrf" and "dgetrs" in the lapack-3.3.0 folder, so I found the object files in $HOME\lapack-3.3.0\SRC but if I include them as well as
$ g++ -O3 main.cc -L$HOME/lapack-3.3.0 -llapack -lblas -lgfortran -I ./include -I $HOME/lapack-3.3.0/SRC -o main
I get exactly the same error which makes somehow sense as they are object files and not header files. What am I doing wrong? How does one manage declarations of functions implemented in external libraries?
Thanks!
I very need to build wxWidgets with clang on Windows for my current project, and I've build wxWidgets 3.0.3 and 3.1.0 on windows with native clang llvm 5.0.0, using mingw-w64 7.2.0, 64 bit, seh, posix threads standard library and tools (x86_64-w64-windows-gnu target). Samples are working. But I'm unable to link dll's except the main one. So I can't build opengl dll in monolithic shared build and all dlls with MONOLITHIC=0. There are some errors with headers/precompiled headers. While compiling I have many redeclared inline; 'dllimport' attribute ignored warnings like:
In file included from ../../src/xrc/xmlreshandler.cpp:18:
In file included from ..\..\include\wx/xrc/xmlreshandler.h:22:
In file included from ..\..\include\wx/window.h:18:
..\..\include\wx/event.h:3750:35: warning: 'wxObjectEventFunctor::operator()' redeclared inline; 'dllimport' attribute ignored [-Wignored-attributes]
inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& even
t)
and then linker undefined reference errors like:
clang_mswuddll-forest\coredll_appcmn.o:(.rdata[_ZTV12wxAppConsole]+0x1e0): undefined reference to `non-virtual thunk to wxAppConsoleBase::FilterEvent(wxEvent&)'
In case of monolithic build I had warnings in compilation stage only in file src/common/glcmn.cpp, so I had compiled a library with command like:
mingw32-make.exe -f makefile.gcc MONOLITHIC=1 SHARED=1 BUILD=debug USE_OPENGL=0 CFLAGS=" -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wno-unused-command-line-argument " CXXFLAGS=" -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wno-unused-command-line-argument -fexceptions -fasynchronous-unwind-tables -fnon-call-exceptions -std=gnu++11 -pthread " LDFLAGS=" -Wno-unused-command-line-argument -fexceptions -fasynchronous-unwind-tables -fnon-call-exceptions -pthread -Wl,--allow-multiple-definition " CC="clang -target x86_64-w64-windows-gnu" CXX="clang++ -target x86_64-w64-windows-gnu"
I had patched only two files while building wxWidgets 3.1.0 vesrion to avoid errors: include/wx/msw/private.h and src/msw/mediactrl_am.cpp
In src/msw/mediactrl_am.cpp I had changed the constant in case:
case -609: // readystatechange in IActiveMovie2 and IMediaPlayer
and in include/wx/msw/private.h I changed lines with errors:
// close the handle in the class dtor
//template <wxUIntPtr INVALID_VALUE = (wxUIntPtr)INVALID_HANDLE_VALUE>
template <wxUIntPtr INVALID_VALUE = (wxUIntPtr)-1>
class AutoHANDLE
and:
static HANDLE InvalidHandle()
{
//return static_cast<HANDLE>(INVALID_VALUE);
return reinterpret_cast<HANDLE>(INVALID_VALUE);
}
It is very difficult to me to install tools like MSYS2 on my job, so I would like to avoid using configure.
Is there a way to repair wxWidgets dlls building with clang in my case?
I am trying to build Essentia (https://github.com/MTG/essentia), an audio analysis library, with Gaia (https://github.com/MTG/gaia) support in Debian 9.0 from source. Before that, one of its dependencies, namely Gaia, was successfully built, also, from source. It was installed in /usr/local/.
When it comes to Essentia, compilation of sources fails with the following errors:
[...]
In file included from ../src/algorithms/essentia_algorithms_reg.cpp:21:0:
../src/algorithms/highlevel/gaiatransform.h: At global scope:
../src/algorithms/highlevel/gaiatransform.h:37:10: error: ‘TransfoChain’ in namespace ‘gaia2’ does not name a type
gaia2::TransfoChain _history;
^~~~~~~~~~~~
../src/algorithms/highlevel/gaiatransform.h: In constructor ‘essentia::standard::GaiaTransform::GaiaTransform()’:
../src/algorithms/highlevel/gaiatransform.h:47:5: error: ‘init’ is not a member of ‘gaia2’
gaia2::init();
^~~~~
../src/algorithms/highlevel/gaiatransform.h:47:5: note: suggested alternative:
In file included from ../src/essentia/algorithmfactory.h:27:0,
from ../src/algorithms/essentia_algorithms_reg.cpp:1:
../src/essentia/essentia.h:46:6: note: ‘essentia::init’
void init();
^~~~
The file where the error lies is /src/algorithms/essentia_algorithms_reg.cpp and here is the command which the file is compiled with:
/usr/bin/g++ -pipe -Wall -std=c++03 -msse -msse2 -mfpmath=sse -O2 -fPIC -pthread -Isrc -I../src -Isrc/essentia -I../src/essentia -Isrc/essentia/scheduler -I../src/essentia/scheduler -Isrc/essentia/streaming -I../src/essentia/streaming -Isrc/essentia/streaming/algorithms -I../src/essentia/streaming/algorithms -Isrc/essentia/utils -I../src/essentia/utils -Isrc/3rdparty -I../src/3rdparty -Isrc/3rdparty/spline -I../src/3rdparty/spline -Isrc/3rdparty/vamp-plugin-sdk-2.4 -I../src/3rdparty/vamp-plugin-sdk-2.4 -I/usr/include/x86_64-linux-gnu -I/usr/include/taglib -I/usr/local/include -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/local/include/gaia2/ -DHAVE_AVCODEC=1 -DHAVE_AVFORMAT=1 -DHAVE_AVUTIL=1 -DHAVE_AVRESAMPLE=1 -DHAVE_SAMPLERATE=1 -DHAVE_TAGLIB=1 -DHAVE_YAML=1 -DHAVE_FFTW=1 -DHAVE_GAIA2=1 -D__STDC_CONSTANT_MACROS -DPYTHONDIR="/usr/local/lib/python2.7/dist-packages" -DPYTHONARCHDIR="/usr/local/lib/python2.7/dist-packages" -DHAVE_PYEMBED=1 -DHAVE_PYEXT=1 -DHAVE_PYTHON_H=1 ../src/algorithms/essentia_algorithms_reg.cpp -c -o/home/hamidi/essentia/build/src/algorithms/essentia_algorithms_reg.cpp.1.o -fPIC -v
g++'s -v option gave me the actual paths visited by the linker (nothing bad in there, I think, but for the sake of completeness):
#include "..." search starts here:
#include <...> search starts here:
src
../src
src/essentia
../src/essentia
src/essentia/scheduler
../src/essentia/scheduler
src/essentia/streaming
../src/essentia/streaming
src/essentia/streaming/algorithms
../src/essentia/streaming/algorithms
src/essentia/utils
../src/essentia/utils
src/3rdparty
../src/3rdparty
src/3rdparty/spline
../src/3rdparty/spline
src/3rdparty/vamp-plugin-sdk-2.4
../src/3rdparty/vamp-plugin-sdk-2.4
/usr/include/taglib
/usr/include/qt4
/usr/include/qt4/QtCore
/usr/local/include/gaia2/
/usr/include/c++/6
/usr/include/x86_64-linux-gnu/c++/6
/usr/include/c++/6/backward
/usr/lib/gcc/x86_64-linux-gnu/6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Here are the files (github repo) involved in the error:
MTG/gaia/blob/master/src/gaia.h
MTG/gaia/blob/master/src/transformation.h#L106
/MTG/essentia/blob/master/src/algorithms/highlevel/gaiatransform.h
It is finally an error that occurred while configuring Gaia that caused the problem. Actually, rather than using merely the following options for configuration:
./waf configure --with-python-bindings --with-asserts --with-cyclops
the option --with-stlfacade was added by inadvertence. This option is not compatible when using Gaia in conjunction with Essentia.
GoogleTest 1.6 with Cygwin 1.7: 'fileno' was not declared in this scope
Error message when building a simple test on Factorial() function in Eclipse CDT:
Invoking: Cygwin C++ Compiler
g++ -std=c++0x -DGTEST_OS_CYGWIN=1 -I"E:\source\gtest-1.6.0\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/challenge.d" -MT"src/challenge.d" -o "src/challenge.o" "../src/challenge.cpp"
In file included from E:\source\gtest-1.6.0\include/gtest/internal/gtest-internal.h:40:0,
from E:\source\gtest-1.6.0\include/gtest/gtest.h:57,
from ../src/challenge.cpp:11:
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1589:51: error: 'fileno' was not declared in this scope
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1595:57: error: 'strdup' was not declared in this scope
E:\source\gtest-1.6.0\include/gtest/internal/gtest-port.h:1627:71: error: 'fdopen' was not declared in this scope
Eclipse CDT 8.1 running gcc 4.7.3 on Cygwin 1.7.22
gTest 1.6 succesfully built including demo tests, with cmake 2.8.9 on Cygwin 1.7.22
I've linked the built lib with full path, E:\lib\gtest-1.6.0\Cygwin\libgtest.a
The following command option was added manually, got same error without it.
-DGTEST_OS_CYGWIN=1
Seems the errors have nothing to do with my code. Anyone using gTest with Eclipse and Cygwin?
Thank you,
unsigned long Factorial(unsigned n) {
return n==0? 0 : n*Factorial(n-1);
}
// Tests factorial of 0.
TEST(FactorialTest, HandlesZeroInput) {
EXPECT_EQ(1, Factorial(0));
}
// Tests factorial of positive numbers.
TEST(FactorialTest, HandlesPositiveInput) {
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
Setting the C++ standard to -std=gnu++0x rather than -std=c++0x, worked for me. You can try the statement:
g++ -std=gnu++0x -DGTEST_OS_CYGWIN=1 -I"E:\source\gtest-1.6.0\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/challenge.d" -MT"src/challenge.d" -o "src/challenge.o" "../src/challenge.cpp"
Setting symbol (-DGTEST_OS_CYGWIN=1) has got nothing to do with this error.
Some functions go beyond the ANSI standard.
These are disabled when you use std=c++11 (or std=c++0x).
Among them are fdopen, fileno and strdup.
There are two possibilities to use them:
Use the GNU dialect (std=gnu++11).
If you want to compile without dialect and make a local exception, you can include stdio.h with the __STRICT_ANSI__ undefined. (see: Error "'fdopen' was not declared" found with g++ 4 that compiled with g++3)
I have tested both on Suse Linux Enterprise 11, MinGW and Cygwin.
Addition: Another (possibly better) way to access non-ANSI symbols would be to add
#define _POSIX_C_SOURCE 200809L
before the first #include in your file. This will give you access to most of the non-standard routines.
Some functions (e.g. realpath(...)) require
#define _BSD_SOURCE
to be inserted on top of your file.