I am trying to include the Raspberry Pi Pico PIO/i2c example in a library within my larger project (to abstract i2c implementations). This seems to work just fine when it is included in a primary executable project (like to example). Within a library, I receive the following compilation error. pis_interrupt0 is a member of the pio_interrupt_source enum from the SDK. Both my main project and library project is using C++ -- while the PIO code is using just C.
In file included from /src/lib/lib_pico_i2c/pio_i2c.h:9,
from /src/lib/lib_pico_i2c/PioI2C.cpp:3:
/src/build/lib/lib_pico_i2c/i2c.pio.h: In function 'void i2c_program_init(PIO, uint, uint, uint, uint)':
/src/build/lib/lib_pico_i2c/i2c.pio.h:87:53: error: invalid conversion from 'uint' {aka 'unsigned int'} to 'pio_interrupt_source' [-fpermissive]
pio_set_irq0_source_enabled(pio, pis_interrupt0 + sm, false);
~~~~~~~~~~~~~~~^~~~
I suspect it has something to do with C++ conversion rules or a missing included of some sort. I have tried to manually include the SDK file that defines pio_interrupt_source with no change. I am relatively new with C/C++ (I do c# in my day job). My reading of C conversion behavior for enums is that there should be an implicit conversion (with no decorations needed). Does being referenced from a C++ file change this? I have tried a number of manual conversion methods with no luck.
you can see the code here: burtonrodman/pico-oled-pio-cpp
Thanks #Paul Saunders,
I have able to fix by adding this to my CMakeLists.txt:
set_source_files_properties(PioI2C.cpp PROPERTIES COMPILE_FLAGS -fpermissive)
set_source_files_properties(pio_i2c.h PROPERTIES COMPILE_FLAGS -fpermissive)
Related
I have created a Qt Widgets Application project. In mainwindow.cpp, I want to add a C source file (mySource.c) from a library which includes some rules written in C language that is not allowed to compile with C++ compiler. One of the error which is appeared is:
error: invalid conversion from ‘const char*’ to ‘gchar* {aka char*}’
When I create a Plain C Application project in Qt, I can simply compile that source. So I need C compiler.
I also used the following code which does not solve the error:
extern "C" {
#include "mySource.c"
}
When I go to the Tools -> Options -> Kits -> Kits, I see Desktop Qt 5.12.0 GCC 64bit and after clicking on it I can see the C and C++ compiler as follows:
C: GCC(C,X86 64bit in /usr/bin)
C++: GCC(C++,X86 64bit in /usr/bin)
I have searched a lot and tested different solutions but I can not solve the problem. What is the solution? Is it a specific flag that I should enable in .pro?
I am trying to understand how wxWidgets actually works. I want to build a C++ GUI app on OSX 10.11.1 just to learn C++.
Now I got wxWidgets from https://www.wxwidgets.org/downloads/ and I got the Linux/OSX version.
I extracted the source and run ./configure && make && make install as I saw from one question in here.
It seemed to have gone on for a while then I got this:
`In file included from ./include/wx/variant.h:401:
./include/wx/any.h:611:5: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData)
^
./include/wx/any.h:167:25: note: expanded from macro 'WX_DECLARE_ANY_VALUE_TYPE'
return wxTypeId(*sm_instance.get()) == wxTypeId(*otherType); \
^
./include/wx/typeinfo.h:84:47: note: expanded from macro 'wxTypeId'
#define wxTypeId(OBJ) wxTypeIdentifier(typeid(OBJ).name())
^
./src/osx/webview_webkit.mm:381:37: warning: incompatible pointer types sending 'WebViewLoadDelegate *' to parameter of type 'id<WebFrameLoadDelegate>' [-Wincompatible-pointer-types]
[m_webView setFrameLoadDelegate:loadDelegate];
^~~~~~~~~~~~
./src/osx/webview_webkit.mm:387:34: warning: incompatible pointer types sending 'WebViewPolicyDelegate *' to parameter of type 'id<WebPolicyDelegate>' [-Wincompatible-pointer-types]
[m_webView setPolicyDelegate:policyDelegate];
^~~~~~~~~~~~~~
./src/osx/webview_webkit.mm:392:30: warning: incompatible pointer types sending 'WebViewUIDelegate *' to parameter of type 'id<WKUIDelegate> _Nullable' [-Wincompatible-pointer-types]
[m_webView setUIDelegate:uiDelegate];
^~~~~~~~~~
./src/osx/webview_webkit.mm:464:34: warning: 'WKPreferences' may not respond to 'setUsesPageCache:'
[[m_webView preferences] setUsesPageCache:NO];
~~~~~~~~~~~~~~~~~~~~~~~ ^
./src/osx/webview_webkit.mm:466:34: warning: 'WKPreferences' may not respond to 'setUsesPageCache:'
[[m_webView preferences] setUsesPageCache:YES];
~~~~~~~~~~~~~~~~~~~~~~~ ^
./src/osx/webview_webkit.mm:936:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
WebBackForwardList* history = [m_webView backForwardList];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/osx/webview_webkit.mm:954:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
WebBackForwardList* history = [m_webView backForwardList];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 warnings and 2 errors generated.
make: *** [webviewdll_osx_webview_webkit.o] Error 1`
and it failed.
I have no idea how to fix it.
Is there an easier alternative I can use?
Also another question that I do not seem to get:
1 - It says it is cross platform. I thought by saying that then there would be 1 source folder that will compile differently on each platform, and not have source code for each platform.
2 - Also, where does it install? will it become part of my os libraries and I would be able to just use it in any c++ program I write?
3 - How can I then move my program to another OSX machine? Will I have to build a self-contained app (like in Java) or will that machine need to have the same wxWidgets version as my machine on which the program was developed?
There are many questions there, it would probably be better to ask each one separately, but let me try to briefly address all of them.
The problem you see is due to an incompatible changes in OS X SDK since the last wxWidgets release, as you could have found out if you searched wxTrac and found this bug. As you can also see there, it's fixed since quite some time, so all you need to do is to get the latest version from GitHub. Alternatively, you can build with older SDK but this is not recommended.
Next:
It is cross-platform because you can write a single version of code that compiles and works on multiple platforms. It's obviously impossible to avoid platform-specific code completely, wxWidgets just encapsulates it for you, so that you don't have to write it.
It installs under /usr/local by default as any Unix library, but this can be changed using --prefix option when running configure.
You should include wxWidgets libraries with your program. The simplest way to do it is to link to them statically. Slightly more involved is to put the shared libraries in your application bundle.
I've been trying to learn unit testing on my own following along a book.
Code in the book use the C++11 standard and have a line like this:
auto variable = function(parameter);
When I first compiled it I got this warning:
warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
No biggie, I could fix that by checking the following box in the Project->Build options... menu:
[ ] Have g++ follow the C++ 11 ISO C++ language standard [-std=c++11]
Now, however, I get new errors related to Google Mock in the gtest-port.h :
| | In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
|1719| error: '_stricmp' was not declared in this scope
| | In function 'char* testing::internal::posix::StrDup(const char*)':
|1721| error: '_strdup' was not declared in this scope
| | In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':|
|1779| error: 'fdopen' was not declared in this scope
Searching for this problem yielded little for me but I did try and define the target OS as it was a suggested solution in case it was not correctly identified automatically. Adding GTEST_OS_WINDOWS=1 and/or GTEST_OS_WINDOWS_DESKTOP=1 in the projects defines changed nothing.
I realize this is easily fixed in this instance by just providing the correct type instead of using auto but I'd like to find a solution for this if possible. Replacing auto and not having the -std=c++11 option checked makes the code work as intended so the library works.
I'm using Code::Blocks 13.12 , MinGW/g++ 4.8.1-4 and Google Mock 1.7 in Windows.
Thanks for reading =)
The answer here lies in the functions which are missing declarations: _stricmp, _strdup and fdopen. The first two are Microsoft versions of the POSIX functions stricmp and strdup. Note that you are specifying the use of the C++11 ISO standard which does not contain items in the POSIX standard. By specifying --std=gnu++11 you are telling the compiler to accept a hybrid of C++11 and POSIX along with GNU extensions.
Interestingly I cannot replicate this with GCC 4.8.2 on Linux so there is the possibility that something else is going on in the Google Mock headers when compiling on Windows.
Answering for anyone still facing the same issue:
The source of this issue might be in your CMakeLists file.
Set your compiler flags to -std=gnu++ instead of -std=c++
One way to do it would be to include
set(CMAKE_CXX_FLAGS "-std=gnu++0x")
to your CMakeLists file.
I need to use MathGL (mathgl.sourceforge.net) for plotting graphs in my Objective-C project but I cant compile it because of semantic issues in files datac_cf.h and canvas_cf.h like:
/usr/local/include/mgl2/datac_cf.h:80:17: 'mgl_datac_get_value' has C-linkage specified, but returns user-defined type 'dual' (aka 'complex<mreal>') which is incompatible with C
/usr/local/include/mgl2/datac_cf.h:206:17: 'mgl_datac_linear' has C-linkage specified, but returns user-defined type 'dual' (aka 'complex<mreal>') which is incompatible with C
/usr/local/include/mgl2/canvas_cf.h:494:17: 'mgl_cexpr_eval' has C-linkage specified, but returns user-defined type 'dual' (aka 'complex<mreal>') which is incompatible with C
there are 7 of them everytime on the "dual MGL_EXPORT ..." line
I have MathGL succesfully compiled using cmake and configured Xcode project header search path to "/usr/local/include" and library search path to "/usr/local/lib", I also dragged and dropped libmgl.7.0.0.dylib to my project..
How can I get rid of these semantic issues please?
I'm using FreeBSD and I have a similar problem. The simplest way to get rid of these warnings is to compile your dependent program with -Wno-return-type or more specifically, with -Wno-return-type-c-linkage flag, which suppresses these warnings.
Other than that, you can patch the headers.
I am trying to build a 3rd party open source project using MinGW. One of the dependencies is wxWidgets. When I try to make the project from MSYS I get a compiler error from
/MinGW/msys/1.0/local/include/wx-2.8/wx/msw/private.h
In function 'COLORREF wxColourToRGB(const wxColour&)':
error: cannot convert 'RGB' to 'COLORREF {aka long unsigned int}' in return
This is somewhat odd given that, according to Microsoft the RGB macro returns a COLORREF.
In fact, looking in H:\MinGW\include I find wingdi.h with the following code
#define RGB(r,g,b) ((COLORREF)((BYTE)(r)|((BYTE)(g) << 8)|((BYTE)(b) << 16)))
What sort of thing would cause this error? Is there some way I can check to see if COLORREF and RGB are being included from wingdi.h and not somewhere else? Is that even worth checking?
Specifications
GCC version 4.7.2
wxWidgets version 2.8.12
(I'm new to C++ and MinGW specifically but generally computer and programming literate)
Try preprocessing the source with -E and check what is actually happening with the macro expansion or whether something is redefining the macro.
The preprocessed source undoubtedly will be very lengthy after #includeing its header dependencies. Your text editor's search function, grep and findstr are your friends here.