Since I am writing a program that will eventually run on Windows and Linux environment compiled from the same project files, I wanted to test and see how well the Operating System directives are. So, I wrote a sample code. The code seems to run unexpectedly or it just my imagination.
Here is the code:
method MainForm.ControlBtn_Click(sender: System.Object; e: System.EventArgs);
begin
{$IFDEF linux}
MessageBox.Show('This is Linux. Horay!!!', 'mypro',MessageBoxButtons.yesno);
{$ENDIF}
{$IFDEF WIN32}
MessageBox.Show('This is Win32. Horay!!!', 'mypro',MessageBoxButtons.yesno);
{$ENDIF}
{$IFDEF CLR}
MessageBox.Show('This is .NET Framework. Horay!!!', 'mypro',MessageBoxButtons.yesno);
{$ENDIF}
end;
Now, when I run this method on Windows it pops up a message box with 'This is .NET Framework. Horay!!!' I kind of expected that being that it was running on Windows. When I ran it on Linux under Mono, it popped up a message box with the same message, "This is .NET FrameWork. Horay!!!" I was expecting to see Linux message, which is "This is Linux. Horay!!!" If this code is working correctly, then how do you check to see which platform your program is running on in the event you do need to execute different methods only supported by Linux or Mac or windows.
The compiler directives are evaluated at compile time (hence compiler directives). So the resulting .exe will always state the platform it was compiled on, not the one it is running on. Also, the Delphi-Compiler directives are not defined in this way for Prism / Oxygene language.
The way to retrieve the OS you're running on is a bit tricky (there are for example multiple values stating you're on UNIX), but not overly complicated.
The first place to go is System.Environment.OSVersion.Platform.
This enum defines the following values in .NET 2.0: Win32S, Win32Windows, Win32NT, WinCE, Unix, Xbox, MacOSX. MacOS has its own value while Linux and other Unixoid systems share the Unix value.
Mono also defines other values too (see the Mono FAQ entry on determining the platform).
Edit: One possible way would be:
var os: string := if Environment.OSVersion.Platform = System.PlatformID.Unix then
'Linux/Unix'
else if Environment.OSVersion.Platform = System.PlatformID.MacOSX then
'Mac OS X'
else
'Windows';
Related
I'm developing code using Golang on windows as it is easier for testing purposes, but the final bin should run on a raspberry pi.
I need to call syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) which works fine however, I need to comment it out on windows to test the binary and uncomment it when building in on the rpi.
Even if I test the os to determine if the function is called, since it does not seem to exist on windows, go won't build it.
Is there a way to build the code on windows even though this function doesn't exist?
I do not wish to do any code edits on the rpi, and i cannot use the wsl i need to communicate with usb devices and such which is easier when building on the native os
It sounds like you want conditional compilation as described here:
https://blog.ralch.com/articles/golang-conditional-compilation/
You could have two source files in your package that use the _os nomenclature as the name. Both files export a function that does the appropriate behavior.
reboot_linux.go
package main
import "syscall"
func Reboot() {
syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
}
reboot_windows.go
package main
import "fmt"
func Reboot() {
fmt.Println("A reboot would have occurred")
}
When you do go build it won't compile reboot_linux.go on Windows. Nor will it compile reboot_windows.go on Linux.
Interestingly enough - this is exactly how Go separates out the implementations of the syscall package in its own source code.
I am trying to load a dynamic library <libname>.so which is present in current directory as well as in /use/lib, /lib, /lib32. but program is not able to find it to any of these path.
I am running a pascal program and it has this method
LibHandle := LoadLibrary( PAnsiChar(Trim('./libtrdp.so')) );
it fails and gives error.
"This binary has no dynamic library support compiled in.
Recompile the application with a dynamic-library-driver in the program uses clause before other units using dynamic libraries.
Runtime error 235 at $0805F292"
if anyone is aware of this issue then please let me know as I have searched on the internet but could not find the answer.
Note: I am running this program on Linux machine.
Add unit dynlibs to the uses clause.
On Linux, loadlibrary is an empty stub that gets filled when you add dynlibs. This is done to keep the base runtime libc+dl free.
Good evening,
I inherited a project made using QT creator (C++ and Qt Quick).
The target is a DaVinci DM8168 board with **Linux kernel 2.6.37 **on it.
In particular I'm using Qt Creator 4.2.0 (4.2.0)
Based on Qt 5.7.1 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit)
I can build & run the application for the target and I can see it running.
I need to launch the profiler. But it does not work. When i run the application (on the target) using the parameter:
qmljsdebugger=port:xxxx
then the application does not start anymore!
I tried to add these options to the project's .pro file:
DEFINES '' += QMLJSDEBUGGER
DEFINES '' += QT_DECLARATIVE_DEBUG
PACKAGECONFIG_append = " qml-debug"
I, obviously, build in debug mode.
When I try to run the applicative on the target i get this message:
QML debugging is enabled. Only use this in a safe environment. Process
killed by signal
I repeat: if the option "qmljsdebugger=port:xxxx" is removed then the application starts and works properly.. but of course the profiler wouldn't connect in this case.
As I said, I've inherited the project and I'm complete new to this environment.
Any help or suggestion?
update
these are now the lines I've added to the .pro file
DEFINES '' += QMLJSDEBUGGER
DEFINES '' += QT_QML_DEBUG
CONFIG += qml_debug
I checked the various path for QT and exported PATH and LD_LIBRARY_PATH.
Unfortunately nothing changes:
If I launch my program using:
/opt/MyPrefix/MyProgram -platform eglfs
then it works.
if I use:
/opt/MyPrefix/MyProgram -qmljsdebugger=port:3456 -platform eglfs
then it crashes
QML debugging is enabled. Only use this in a safe environment.
Segmentation fault
the program seems to start in Debug Mode and this is ok. The problem is the profiler :(
ps: As far as I know there are no firewalls running on the target. I'll check better for sure.
update 2
I tryed the same solutions as above but on a simple program as suggested(an "hello world" basically) and it does not crash when the "-qmljsdebugger=port:3456" option is specified... I really don't know what the problem is in my original application.
First there are a few prerequisites to make qml debug run like being sure that Qt was built with the exact same toolchain as the binary. You should take a look at Qt Wiki: https://wiki.qt.io/How_To_Profile_QML_App_on_Embedded_Device
An important note is that how you make qml debugging works has changed between Qt Quick 1 and Qt Quick 2. As you are using Qt 5, I believe you should be using Qt Quick 2. So that means that you should not use QT_DECLARATIVE_DEBUG, but QT_QML_DEBUG.
More details: https://doc.qt.io/qt-5/qtquick-debugging.html#qml-debugging-infrastructure
If you still have issue after using the proper DEFINES and making sure that evry prerequisite was met, then you should try with a basic Qt program that does nothing, but display a simple QML item (like a Rectangle or a Button) ans see if you still have the issue.
In the C++ code (C# solution is OK: I can translate it to pure C++ or C++/CX) I need to check whether the code is working under Windows Phone 10 or not.
Rely on assumes which editions/SKU support which functions is a terrible bad design.
Call the D3D11CreateDevice call with D3D11_CREATE_DEVICE_DEBUG in Flags and if it returns DXGI_ERROR_SDK_COMPONENT_MISSING the debug layer is not avaible and call it again without this debug flag so that it works on Phone/Mobile, too.
Searching for D3D11_CREATE_DEVICE_DEBUG here on stackoverflow shows this topic on steps how to install the required data on mobile.
I'm attempting to package Mnemosyne, an application that uses PyQt, on Mac OS Lion via Py2app.
I'm getting several errors like the following:
objc[2826]: Class QCocoaView is implemented in both
/Volumes/Bullfrog/patrick/m2/./dist/Mnemosyne.app/Contents/MacOS/../Frameworks/libQtGui.4.dylib
and /opt/local/lib/libQtGui.4.dylib. One of the two will be used.
Which one is undefined.
objc[2826]: Class QCocoaWindow is implemented in both
/Volumes/Bullfrog/patrick/m2/./dist/Mnemosyne.app/Contents/MacOS/../Frameworks/libQtGui.4.dylib
and /opt/local/lib/libQtGui.4.dylib. One of the two will be used.
Which one is undefined.
The first version of the class is the one used in Py2App and is the one that should be used (I am trying to make the app standalone). The second is the system Qt that I installed via MacPorts. What do I have to add to the application to make it use the bundled Qt and not the system Qt?
And also several statements like this:
On Mac OS X, you might be loading two sets of Qt binaries into the
same process. Check that all plugins are compiled against the right Qt
binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of
binaries are being loaded. QObject::moveToThread: Current thread
(0x10246c880) is not the object's thread (0x106985d00). Cannot move to
target thread (0x10246c880)
Honestly I don't really understand how to do what I need to do here just based on this error message (I'm not a coder; I'm just doing my best to package the software).
This article gives a solution: simply add a blank qt.conf file in the application's Content/Resources directory.