How to get code that uses x86intrin.h to run on MAC - c++

I am trying to get the code for clhash to run on MacOS Big Sur. The problem is that it uses #include <x86intrin.h>, which leads to many error messages like:
In file included from /Users/myusername/Scripts/projectname/clhash.c:5:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include/x86intrin.h:15:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include/immintrin.h:17:
/Library/Developer/CommandLineTools/usr/lib/clang/13.0.0/include/mmintrin.h:50:12: error: invalid conversion between vector type '__m64' (vector of 1 'long long' value) and integer type 'int' of different size
return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I understand this has something to do with apple not using Intel processors. I am using the CLion environment, which uses CMakeLists for linker stuff. How can I fix this error?

Related

C++ enum addition and conversion (Raspberry Pi Pico PIO)

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)

Building C++ openCV project on Windows 11 will not build, works fine on Mac

When I configurate the source code in Cmake with configurator Mingw Makefile, I get no errors, when I proceed to the terminal and write "make" in the correct folder, I get the following error in termianl:
error: cannot convert 'const value_type*' {aka 'const wchar_t*'} to 'const char*'
This line causing this problem is this:
int nbr = (int) std::strtol(entry.path().filename().c_str(), nullptr, 10);
Previously I've run the exact same code on Mac with 0 issues.
Running on Windows 11.
Any ideas on how this can be solved?

Xcode QuantLib building error: loses integer precision and no template named 'forward'

I'm writing C++ with Xcode 7.2.1 and want to use QuantLib 1.7.1. I installed the package following the instructions on quantlib.org and changed project settings according to this essay
https://www.scribd.com/doc/210157027/QuantLib-1-4-Xcode-4-5-2#
But when I build the project, there are always two types of errors:
Implicit conversion loses integer precision: 'long' to 'Day' (aka 'int')
No template named 'forward' in namespace 'std'; did you mean simply 'forward'?
I tried to use QuantLib 1.6.2, but the problem remained the same. How can I solve these problems?
Update:
Second problem solved. Only two types of first problem remained: loses integer precision and unused variable issue. Here is a snapshot.
http://imgur.com/5PJpyo5

Starting with wxWidgets and C++

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.

How to include Accelerate framework with i686-apple-darwin11-llvm-g++-4.2?

I am trying to use the Accelerate framework on a small C++ program. I'm not even using XCode, only a simple Makefile.
The compiler complains when I add the following line to my code:
#include <Accelerate/Accelerate.h>
The error is the following:
In file included from /System/Library/Frameworks/vecLib.framework/Headers/vecLib.h:41,
from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
from Diana.cpp:20:
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected identifier before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected `}' before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected unqualified-id before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9028: error: expected declaration before ‘}’ token
The compiler I'm using is i686-apple-darwin11-llvm-g++-4.2, which is a gcc 4.2.1, and the line that I use to compile (not to link) is:
i686-apple-darwin11-llvm-g++-4.2 -D__MACOSX_CORE__ -c -o Diana.o Diana.cpp
Should I add some additional flag(s) when compiling this? I tried adding the "-framework Accelerate", but it doesn't change anything, since this should only be included in the linkage process (am I right?).
I googled some of these error messages and I didn't find anything.
I would really appreciate any help. Thank you!
PS: My OS X version is Lion 10.7.5, and XCode is 4.4.1.
I figured it out: I checked what was on line 9008 of vDSP.h and the problem was that I was declaring an FFT_FORWARD constant before including the Accelerate.h.
Fixed!