Can the Swift compiler create a single executable for my application? - swift

I'm currently trying to create an executable for my Vapor application, but I just can't run it on my server.
My expectation was that it would be able to create a single application with all my code and the dependencies. My current references are .NET and Go, where you can create a single executable from the code and deploy this standalone file - which makes it amazingly simple to deploy.
I tried compiling and executing it on Docker, but no such luck - it failed with some libSwift something missing.
So, can Swift do something like this?
Looking forward to your answers

You can build a binary that statically links the standard library or build a completely self contained binary using the static linking flags introduced in Swift 5.3.1 - -static-stdlib and -static-executable. See this forum post for more details.
Note that swift still has some dependencies on ICU and libc so aren't completely portable yet

Related

I can't import MacPorts' /opt/local/include/ncurses.h into my Swift project. It conflicts with macos SDK /usr/include/ curses.h. Any hint?

EDIT: Getting negatives for such a detailed and HONEST question? Sometimes I don't really get Stack Overflow. Really.
Hi, I'm trying to create a PoC using Swift 5 (Xcode 10.2.1) and a modern rendition of ncurses (in this case, MacPorts' one, some 6.1.2018XXXX version)
My Poc has no code as of now, as my problems start before being able to add any sensible line to my .swift files.
So far I've done the following things:
1.- I have a proper working MacPorts ncurses library installed: that means "sudo port install htop" can build "htop" application without any problem, proving that way that my ncurses library is correctly installed (.h files seem to be deployed inside /opt/local/include/ directory)
2.- I create an empty CONSOLE APPLICATION swift program (using Xcode 10.2.1 own wizard). It just takes 4 mouse clicks, and you get some "Hello world" silly main.swift file.
3.- I create a bridging header to import my .h files (in this case ncurses.h).
The contents of this bridging header will/should be something like this:
#import "/opt/local/include/ncurses.h"
4.- I compile and run the silly empty "hello world" swift program, and I get tons of somewhat "expected" errors. Something like:
"Darwin/SDK curses.h symbol xxxxxxxxx is also defined inside your /opt/local/ncurses.h file. Bailing out." (it's not the literal error I get, you just get the idea)
So my question is:
Can I disable/remove Darwin/internal/MacOs SDK curses.h from my XCode project definition somewhere, in order my bridging header only sees one copy of my 2 (n)curses.h file (that should be my macports one)?
I've tried many things described in this other thread, but with no luck: How to disable "curses.h" header (a part of "stdio.h in Xcode 6.3 OSX Yosemite) to avoid conflicting function declarations
Specially "Enable Modules" option, which no matter the value you set it to, seems to do nothing.
BTW: I know when I might solve this .h headers issue, I will probably need to add some additional -lib linking option in the "build phase"(?) tab inside Xcode, but I'll try to manage myself when that moment arrives.
As of now my concern is "I wan't to remove Apple Internal Macos SDK curses support/files from my Xcode project". Is it achievable?
PS: I'm using Mojave 10.4.4 with no problem
I'm having the same issues, although trying to use ncurses via the Swift Package Manager. Despite being actively trying to find a solution I've been unsuccessful so far. Check my question just in case: Swift package manager unable to compile ncurses installed through Homebrew
This answer should give you all the information you need to get it working :) https://stackoverflow.com/a/56728436/554972

Can't Compile Tesseract API example for WIndows using Tesseract 3.0.2.02 archive

I'm looking at using Tesseract to do some work with PDF files, and so I want to use the library rather than an external executable.
I started by downloading the full Tesseract source and looking at building that. Sadly the standard sources don't have any means to build on a non-Linux platform, in my case Windows. There are methods for doing so, and I looked at those.
Firstly the VS2008 build doesn't. I'm aware that it need Leptonica, but I figured I'd tackle that afterwards and just tried to build the existing code. Fails with "fatal error C1083: Cannot open include file: 'allheaders.h': No such file or directory". Nothing to do with Leptonica at this stage, it simply doesn't work.
Even if I were able to get past that, I'd have to build Leptonica, and that requires using GNU tools and therefore an installation of Cygwin, so I gave up. I Have a MingW instatllation, (I've never managed to get Cygwin to work in a usable fashion) but I'm not keen enough to mess with such a complicated and fragile build.
So I decided I'd just use the pre-built binaries which some kind soul creates. Downloaded that from code.google.com. Now I need to look into using the code, so the next obvious step is the Tesseract API example, which states it requires "tesseract-ocr-3.02.02-win32-lib-include-dirs.zip", no problem, because I already have that now.
No real clue as to where the API example wants the files to be placed, but a little messing about gets them in appropriate locations. Press build and "fatal error C1083: Cannot open include file: 'allheaders.h': No such file or directory", just like trying to build Tesseract from source.....
And indeed there is no such file.
So, where is this file ?
I also struggled some time ago to make it works under windows and then I found this git repository : https://github.com/charlesw/tesseract-vs2012
It includes all needed extern library (because Tesseract need Leptonica, but Leptonica also need extern library to handle the different image format) and is also working great with vs 2013.
OK so now I see that allheaders.h is part of Leptonica. Still leaves me wondering why the Tesseract pre-built library requires that I have Leptonica available, I would have expected that to be built-in, I guess it isn't.

Linking Qt Libraries to a Cmake project (in eclipse)

so what I'm trying to do is utilize a simple Qt application IN eclipse without using the eclipse QT plugin by linking the required libraries through the GCC C++ Linker. However, I have been unable to locate the exact name of the library to use, or which libraries will be necessary. I've located the path of the Qt library my application seems to be accessing, but I continue to get an error when building that just says "-lqt" doesn't exist/can't find, etc.
The reason I'm doing this is because I'm building a simple game in OGRE for a project at the uni and wanted to use a Qt application for the GUI. Well, I didn't necessarily want too, but our professor wishes us to do so. Please don't suggest that I simply embed an Ogre widgit into my Qt application as this isn't an opti
Any ideas?
Thanks <3
Well, if you are using CMake then it should take care of everything provided that you instructed it to do so. phb provided a link to even better instructions.
First step is to instruct the CMake that we need Qt for our project. This is done with (you can specify individual parts that are needed as well):
find_package(Qt4 REQUIRED)
If Qt is not found in the typical locations (e.g. QTDIR is not set) - cmake will fail.
You also have to instruct CMake to use Qt include paths and set certain compiler definitions:
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
Finally, for each target you need to tell that you'd like to link with Qt libraries:
target_link_libraries(foo ${QT_LIBRARIES})
You might also want to process your headers and will have to process the user interface files with moc. For the details please refer to the provided links.
In addition to provided links you can have a look at the comments at the top of FindQt4.cmake file.

Using Soap in Shared Mono Library for WP 7 and Android

I'm currently working on an shared library based on mono, where I want to put as much business logic of my app as possible.
I used this helpful tutorial.
I managed putting the whole logic for rest-requests in this shared library, but now I'm stuck with soap.
I used the wsdl command of mono to generate Client Stubcode from my wsdl (as described here http://www.mono-project.com/Web_Services).
When I put the generated class to my C# library, which is the root project of my shared library, there is a warning that the Reference to System.Web.Services cannot be found.
So I included the System.Web.Services.dll manually.
For the Android Library Project I added a Reference to ...\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Web.Services.dll. It compiles without warnings.
But now it comes to the Windows Phone Library Project.
There is no System.Web.Services.dll for WP 7.5, right? I tried with the Mono-Touch dll but it gives me a lot compilation Errors.
Someone knows how I can get out of this?
I actually had some issues with the generated WSDL myself. Turns out that the classes that were generated through the "Create Web Reference" piece of Visual Studio inside of a Mono for Android project ended up causing some big issues when connected to a WCF Web Service. Not sure where I ran into this information, but this is what I ended up doing.
What you need to do is manually create a Service Reference using the SILVERLIGHT SVCUtil.
On my development system it was located here:
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v3.0\Tools
I called it with the below command line:
slsvcutil.exe http://localhost/<path to WCF service endpoint>/service.svc /directory:"<temp directory to store generated cs file>" /noConfig /namespace:"*,<Full namespace of the generated class>"
That will actually generate a CS file that is saved into the path specified by the /directory tag above. Copy that generated cs file to your project directory and then include it in the project.
The problem that I was having that forced me to look for another option was that I was able to pull the data properly using the WSDL generated through the "Add Web Reference" option in Visual Studio, but as soon as I tried to pass the data back up the wire to the web service, everything blew up. Using the Service Reference generated by the Silverlight Service Util actually generated all the code properly for Async operations and after learning how to properly manage those Async operations everything works like a dream.
Since you are generating this new WSDL using the Silverlight Utility, it should work just fine through Windows Phone 7. I believe that the DLL to reference for all of this is the System.ServiceModel dll.
I wish I could remember where I ran across this information, as I would like to give the original author credit, but unfortunately, I don't recall that.
Hope that helps out!
Chaitanya Marvici

Correct configuration to build libsrtp for the iphone?

I'm trying to build libsrtp so that I can use it on the iPhone (I intend to use it with libav's implementation of RTP).
My configuration:
./configure
--build='arm-apple-darwin9'
The warning I get when I attempt to call srtp_init():
file was built for unsupported file
format which is not the architecture
being linked (armv7)
Followed by the error:
"_srtp_init", referenced from:
+[Manager initialize:] in Manager.o
Symbol(s) not found
Does anyone know the proper configuration for building the library correctly?
The problem is it's not being built for ARM (or not for the right ARM; you need to look at which compiler is bing invoked with which options, and compare it to one you know is working). Did you do rebuild configure with autoconf? See the GNU build system wiki page for a starting point on how to reconfigure the build for other systems/processors.
FYI, if you find a bug in the configure.in or other parts of libsrtp, please let me know - I'm an author on it with checkin privs.
For general guidelines on cross compiling libraries for iOS I recommend this article:
http://tinsuke.wordpress.com/2011/02/17/how-to-cross-compiling-libraries-for-ios-armv6armv7i386/
The same guy also wrote an updated version for iOS 5. This one is specific to the tesseract library, but the general principles are the same:
http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/.
Using these as a guide I've had some success compiling a few libraries. Key things to note are that you have to disable compiling shared binaries. Also I recommend using clang rather than gcc.