Reference something from a shared project - web-services

So I am using Xamarin to create an Android App. All the android "stuff" will be in the Android project and I have created a Shared Project to house the business logic, so that I will be able to use it should I have to create an IOS app.
I have successfully referenced the Shared Project from the Android project - so far so good. So my Database code is in the shared project ready for any platform to use.
My app needs to connect to a webservice, so I wanted to house all that in the Shared Project but there seems to be no way to add references (web or otherwise) to a shared project - is this correct? surely it can't be or I wouldn't be able to use JSON.net in the Shared project or anything else that requires a reference to an external DLL...? Which would result in me duplicating any code like this multiple times, once in each platform.
Surely I am missing something here - any Google search returns how to reference a shared project from another project...Not what I need.
So the question is, can I add references in a Shared Project to a web service/3rd party DLL, if so, how do I do it?
Thanks for any help.

It's not possible to use reference directive in Shared project. You will have to instantiate the references on the platform specific project (Project.iOS) and pass it to the class in the shared project.
Use AppDelegate to define web Services references.

iOS Apps can't use shared libraries that you create yourself. The only ones you can use are those provided by Apple, in the System frameworks, that you'll find in the iOS SDK.
You can use static libraries. That might or might not solve your problem.
Possibly Xcode is enforcing this rule.
For a simple test, can you share a single source file, rather than a library?
Also they aren't called "DLLs" on iOS or Mac OS X, they're called "dylibs".

Related

Native DLLs not loaded from PATH in ASP.NET WebApi

I am currently trying to basically expose a native C++ library, that I not have the code for, as a WebApi. To do that, I created a managed C++ wrapper library, that allows my web application to communicate with the native code.
So the dependencies of the project look something like this:
Web application (ASP.NET)
Managed C++ Wrapper
Native C++ Library (DLL)
Native Dependencies (DLLs)
My problem is now, that I always get the error message "Could not load file or assembly [ManagedWrapper.dll] or one of its dependencies. The specified module could not be found."
Since the managed wrapper library is in the same solution, it is listed as reference and even copied to the shadow copies, so I assume that the problem lies in the native dependencies. I am well aware that there are problems with loading native DLLs in ASP.NET as no shadow copies will be made of them and they can not be added to the GAC. I tried to tackle this problem by just adding them to my %PATH%, but the error still remains. Dependency walker did not show any additional dependencies and adding the native DLLs to system32/inetsvr fixed the problem, but this is obviously not the way this should be done.
So here my question: What could be the reason that the PATH variable is not working? (And is there maybe another way to get this to work?)
Using loadLibrary to load with an absolute path is not really a possible solution as I have no influence on the native C++ library and how it will load further dependencies.
I think I found my own a solution to my problem and hope this might help someone else as well:
My native DLLs where somewhere in my home folder. Moving them to a more accessible place, i.e. C:\temp\, and adding this folder to the path seemed to do the trick. My guess is, that this was a permission based problem, even though I added rights for IUSR for that folder in my home directory before.

Resolving/publishing C/C++ dependencies with Gradle and Artifactory?

I want to ease adoption of dependency management in my organization, and it does not seem to be as easy of a task with C/C++ as it is with Java.
I want to use an internal Artifactory repository (Maven, Ivy, Gradle or whatever is suitable) to essentially be able to download and publish external libraries which have been precompiled to then statically link them (catch: we are using a custom compiler for an embedded platform)
I have read what it seems to be the basic guide from Gradle's website, however there is no mention of external repositories:
https://docs.gradle.org/current/userguide/native_software.html
http://gradle.monochromeroad.com/docs/userguide/nativeBinaries.html
These two threads seem to touch on the subject, but I'm confused as to where the linking is happening and in what order:
https://discuss.gradle.org/t/external-dependencies-in-cpp-projects/7135
https://discuss.gradle.org/t/right-way-to-copy-contents-from-dependency-archives/7449
So far I cannot wrap my mind around some of the closures/syntax and correct usage of stuff like "configurations", "dependencies", "repositories" because they seem to be used in different ways.
With all that said, what would be a minimal example to get the following done?:
Go to Artifactory
Fetch a dependency (let's assume it is a .a or .o file)
Put that individual dependency in a specific location within the project
Build (specifying the linking order and compiler)

Easy way to build multi platform C++ library with Xcode

I want to build a C++ library for Mac and iOS using the same Xcode project. When I'm creating a new project in Xcode I can choose Mac OS C++ library, but there is no similar option for iOS. The code is exactly the same on both platforms and I don't see any point having 2 different projects.
Can you provide me some guidance to achieve this?
EDIT: Now I'm using same project with different targets, one for Mac and one for iOS
Depending on what you want to use this library for, creating an iOS fake framework may also be an option: https://github.com/kstenerud/iOS-Universal-Framework/tree/master
I usually create both (libraries and (fake) frameworks) for a) binary-delivery only SDK projects or b) very fat libraries which are rarely changed but often used. An example for the latter is SQLite, which takes very long to compile for iOS and is maybe changed once a year. But for debugging purpose, I use the same project and code base using a static library target (for when we update the fake framework once in a while and need to debug it).

Packaging a modified Qt class

Heads up, this is going to be confusing:
I customized 9 files from Qt5.2: qquicktextdocument.cpp qquicktextdocument.h qquicktextedit.cpp qquicktextedit_p.h qquicktextedit_p_p.h qquicktextnode.cpp qquicktextnodeengine.cpp qquicktextnodeengine_p.h qquicktextnode_p.h
Each file is simply prefixed with a letter and still inside /qtdeclarative/src/quick/items/. I am 100% happy with the modifications I made being put under GPL etc. I somewhat want my end application (discussed below) to be Apache or MIT, but, I'm flexible.
My modifications work fine. When I modify a few additional files I am able to compile them along with the rest of Qt (at the same time, using the same make command). But these modifications are going into another Qt application that I am making which I want other people to be able to use, and requiring general consumers to have a custom compiled version of Qt would be obviously absurd.
I want to package/compile/do something, that will enable me to include the modifications in my final project as a shared library, or something.
As a web developer writing C++ and Qt, I am very confused about linking shared libraries, header files, etc.
To recap, I modified Qt 5.2 and made a custom compilation of it for an application I am building, and I want people to be able to run that application without having to have a custom compilation of Qt. I need a way to decouple my Qt modifications from Qt.
I realize this might be a big topic, I'm not expecting a step by step guide, just some general guidance. So far I have tried compiling my modified files as a library, then including that library in my actual project, but I am getting undefined references and missing files all over the place. (I don't know if I did anything right)
I am also currently looking at subclassing the classes I want but I'm unsure about this. It might require copy pasting some code, which could have licensing issues?
end goal: be able to have a wavy underline (in qml) for incorrectly spelt words.
Thank You.
My 5 cents.
If your changes can be useful (in general) to other people you can try to push them to upstream via codereview.
If you want your application to run only in windows everything become obvious: in windows it is normal to provide your application with shared libraries (to avoid DLL HELL). Btw, have you heard about static linking?
Qt has some plugin mechanism. You can compile your code into shared object (dynamic library) and install it with your application. For example, QML FolderListModel do this. You can look at code in $qt5_src/qtdeclarative/src/imports/folderlistmodel.

How to import and use QObject in a BB10 Cocos2D based app

I am currently working on building a Cocos2d-x game for the BB10 platform using the BBTemplateProject sample provided with Cocos2dx. I am new to C++ programming, and the current game is a port of a java project Iv been working on for a while. In order to save game data (scores, some settings etc), I intend to use the QtSQl Library which BB10 provides.
I have successfully run some sample Qtsql code in a sample Cascades application and it works fine.
However, integrating the same code into my Cocos2dx BB10 project just doesnt work .
I use the momentics IDE and have added the qt4, QtCore, QtDeclarative, paths/symbols to the project but still recieve the following errors
undefined reference to `QObject::QObject(QObject*)'
undefined reference to `vtable
undefined reference to `QSqlDatabase::defaultConnection'
.. and a bunch of other Q- related object errors.
After reading up on Qobject here http://developer.blackberry.com/cascades/reference/moc.html
I suspect that the MOC compiler is not appropriating referenced or a similar issue. Also, given the same code works well when integrated in an auto generated cascades project in the Momentics IDE, I am led to believe it is some sort of moc compiler issue. Given that I am quite new to C++ development, I still havent been able to figure out how to add the appropriate qmake file rules to the Momentics IDE in order to recognise Qobjects . Help is needed in this area.
Will definitely appreciate any pointers on how to go about this from experienced c++ devs or better ways to store data within cocos2dx blackberry 10 projects.
Thanks in advance.
Edit :
Here's , my progress thus far in trying to use QtSql for database interaction. QtSQl requires QtCore which contains QObject above. Thus far I have been unable to successfully integrate QtCore library.
I have done the following.
Added the /usr/include/qt4 and /usr/include/QtCore and /usr/include/QtSql to my include list using the following procedure
Right click over your project in Project Explorer and choose Properties
Expand the tree to C/C++ General / Paths and Symbols
Change the Configuration in the Paths and Symbols frame to [All configurations]
Click the Includes tag and select GNU C in the Languages list (or do this for every language).
Click Add... and type ${QNX_TARGET}/usr/include/qt4 and press OK
Click Add... and type ${QNX_TARGET}/usr/include/qt4/QtCore and press OK
Used the Momentics IDE add library function to add both QtCore and QtSql to the project. RightClick->configure->add Library and Standard BlackBerry Platform Library. The library gets added successfully.
I basically followed the steps detailed in this related post Adding QtCore Library in blackberry 10 sdk . But now get this error.
\win32\x86\usr\bin\ntoarm-ld: cannot find -lQtCore
The OP in that post mentions solving "some linker problems" but fails to mention how. I have also tried modifying the bar-descriptor.xml file adding the following lines
<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>
<asset path="${QNX_TARGET}\${CPUVARDIR}usr\lib\qt4\lib\libQtCore.so" type="Qnx/Elf">lib/libQtCore.so.4</asset>
Error still remains.
How do I solve this "linker" or library-no-found error ? Many Thanks.
First, if you plan to use the same application on both BlackBerry 10 and, I guess, Android as you are coming from Java, I'd try to use something smaller than Qt, like SQLite library, to keep it as simple as possible to port between the two platforms. But you can obviously use QtSQL on BB10 and something else in Android, you'll just have more code to write.
Second, regarding your issue: the undefined reference to QObject::QObject(QObject*) means that you are using this symbol (the QObject constructor, which you are probably calling because one of you class inherits from QObject), but nothing is providing it. You have probably added QtCore to your include path as the compiler found it, but not the linker: you need to specify that you want your application to be linked with QtCore.so (or maybe QtCore4.so, I don't have the SDK right now to check the exact name). You'll find everything you need on how to do this here.
About moc: moc stands for Meta Object Compiler. It basically parses your headers, looking for metadata on your classes: mainly properties, signals and slots. More specifically, everything that requires the Q_OBJECT macro. If you don't use theses functionalities, you don't need to run moc.
If you have to run it (because you use some meta object functionalities): you have two options. Option one: use QMake to compile your project. You'll have to recreate your project from scratch as a Qt project (maybe not differentiated of Cascades projects on Momentics, however it's just a matter of removing libraries you're linking to, not a big deal) to do this. Option two: add custom rules to run moc on headers needing it. It will generates some moc_yourclass.cpp files that you'll need to include in your project. I don't know how to do add a custom step on Momentics, but I think it should be doableā€¦