how to static add openssl with c++ builder? - dll

I am able to use openssl in the source code below, but without the libeay32.dll file, my project does not open. I want to add it static and eliminate the need for dlls. How can I do that ?
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <openssl/bio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma comment(lib, "libeay32.lib")
#pragma comment(lib, "ssleay32.lib")
TForm1 *Form1;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BIO* key;
void* buf;
key=BIO_new_mem_buf(buf,100);
}
//---------------------------------------------------------------------------
I tried to compile statically but without success.

Related

Why calling objc function from objc++ could result in build failure?

Given this MVP code:
objc_funcs.h
#import <Foundation/Foundation.h>
NSString* doFoo(void);
objc_funcs.m
#import <Foundation/Foundation.h>
NSString* doFoo()
{
return #"fffuuu";
}
main.mm
#import "objc_funcs.h"
int main(int argc, char * argv[]) {
doFoo();
return 0;
}
If I leave it this way, the build will result in
Undefined symbols for architecture x86_64:
"doFoo()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Though if I rename main.mm -> main.m, the build will go just fine.
WAIDW? 😖
The problem relates to C vs C++ linkage.
The normal way this is handled in C headers is testing for the __cplusplus preprocessor macro and inserting an extern "C" if needed. CoreFoundation provides the CF_EXTERN_C_BEGIN and CF_EXTERN_C_END macros that handle this:
#if !defined(CF_EXTERN_C_BEGIN)
#if defined(__cplusplus)
#define CF_EXTERN_C_BEGIN extern "C" {
#define CF_EXTERN_C_END }
#else
#define CF_EXTERN_C_BEGIN
#define CF_EXTERN_C_END
#endif
#endif
Using these your objc_funcs.h becomes:
#import <Foundation/Foundation.h>
CF_EXTERN_C_BEGIN
NSString* doFoo(void);
CF_EXTERN_C_END
if you don't want to use them you could use
#import <Foundation/Foundation.h>
#ifdef __cplusplus
extern "C"
#endif
NSString* doFoo(void);
You have to make it valid for C++ compiler by either converting objc_funcs to .mm file or wrapping the import in main.mm with extern "C" {}:
extern "C" {
#import "objc_funcs.h"
}
You could read more about it here

Windows SDK - Only for DirectX-Apps?

because I habe problems installing the DirectX SDK June (11), I read that Windows 8.1 users already have the DirectX 11 SDK integrated - in the Windows-SDK. But nevertheless, I could not get the info (even not from MCs article "Where is the DirectX SDK) if this SDK only offers the possibility to write DirectX-Apps (Win 8-Apps). If it also supports writing normal desktop-programs:
Do you know how I can set up a normal Win32-Project using DirectX from the Windows-SDK.
#pragma region COM
#include <guiddef.h>
#include <OCIdl.h>
#include <Unknwn.h>
#include <Objbase.h>
#pragma comment(lib, "Ole32.lib")
#include <OleCtl.h>
#pragma comment(lib, "OleAut32.lib")
#include <comutil.h>
#ifdef _DEBUG
#pragma comment(lib, "comsuppwd.lib")
#else
#pragma comment(lib, "comsuppw.lib")
#endif
#pragma region WIC
#include <wincodecsdk.h>
#include <wincodec.h>
#pragma comment(lib, "windowscodecs.lib")
#pragma endregion
#pragma region D2D
#include <d2d1.h>
#include <d2dbasetypes.h>
#include <d2d1helper.h>
#include <d2d1_1.h>
#include <d2d1_1helper.h>
#include <d2d1_2.h>
#include <d2d1_2helper.h>
#include <d2d1effects.h>
#include <d2d1effecthelpers.h>
#include <d2d1effectauthor.h>
#pragma comment(lib, "d2d1.lib")
#pragma endregion
#pragma region DWrite
#include <dwrite.h>
#include <dwrite_1.h>
#include <dwrite_2.h>
#pragma comment(lib,"dwrite.lib")
#pragma endregion
#pragma region D3D
#include <dxgi.h>
#include <d3d11.h>
#include <d3d11_1.h>
#include <d3d11_2.h>
#include <DirectXMath.h>
#include <DirectXColors.h>
#include <DirectXCollision.h>
#include <DirectXPackedVector.h>
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#ifdef _DEBUG
#include <d3dcompiler.h>
#pragma comment(lib, "d3dcompiler.lib")
#endif
#pragma endregion
#pragma region XAudio
#include <Xaudio2.h>
#include <x3daudio.h>
#pragma comment(lib, "Xaudio2.lib")
#pragma endregion
WIN32 SDK D3D + D2D + XAudio + WIC includes and static libs. Put these in your pch.h or stdafx.h after <windows.h>.
And the Desktop DirectX Graphics Reference links:
Direct3D11
Direct2D
DirectWrite
XAudio2
Of course it's possible to writing an normal Directx desktop programs with the Win8 SDK since DirectX SDK now a part of the Windows SDK, and you can build a desktop app with the Windows8 SDK just like old DirectX SDK just include your header, link your library and write your app, Just be aware that this SDK don't supports writing app to older version of DirectX (DirectX9, 10) and older it's only supports DirectX11,
If you want to writ a app to older version of DirectX then use the old one SDK

QT run objective-c code

I'm trying to run native object-c code on my Mac application.
My code looks like:
MainWindow.h:
#ifdef Q_OS_MAC
#include <Carbon/Carbon.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <mach/mach_port.h>
#include <mach/mach_interface.h>
#include <mach/mach_init.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
#endif
MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifdef Q_OS_MAC
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: #selector(receiveSleepNote:)
name: NSWorkspaceWillSleepNotification object: NULL];
#endif
}
#ifdef Q_OS_MAC
- (void) receiveSleepNote: (NSNotification*) note
{
NSLog(#"receiveSleepNote: %#", [note name]);
}
#endif
But am getting errors that seems that QT does not understand the code structure:
application.cpp: error: expected external declaration
- (void) receiveSleepNote: (NSNotification*) note ^
In order to compile objective-c with C++, you need to have the objective-c code in a .m or .mm file.
The accompanying header can then contain functions that can be called from C++ and the body of those functions can contain objective-c code.
So let's say, for example, we wanted to call a function to pop up an OSX notification. Start with the header: -
#ifndef __MyNotification_h_
#define __MyNotification_h_
#include <QString>
class MyNotification
{
public:
static void Display(const QString& title, const QString& text);
};
#endif
As you can see, this is a regular function in a header that can be called from C++. Here's the implementation:-
#include "mynotification.h"
#import <Foundation/NSUserNotification.h>
#import <Foundation/NSString.h>
void MyNotification::Display(const QString& title, const QString& text)
{
NSString* titleStr = [[NSString alloc] initWithUTF8String:title.toUtf8().data()];
NSString* textStr = [[NSString alloc] initWithUTF8String:text.toUtf8().data()];
NSUserNotification* userNotification = [[[NSUserNotification alloc] init] autorelease];
userNotification.title = titleStr;
userNotification.informativeText = textStr;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
}
The implementation contains objective-c and due to its .mm file extension, the compiler will handle this correctly.
Note that in the example you provide in the question, you need to think about what the code is doing; especially when using 'self', as I expect that would need to refer to an Objective-C class, not a C++ class.

OSX command line app linker error

I have created an OSX command app in Xcode 5
Here is the main.m
#import <Foundation/Foundation.h>
#import "ConnectionListener.h"
#import "SOMatrix.h"
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSLog(#"Hello, World!");
print_m();
}
return 0;
}
and here is my header file:
#ifndef __GDC1__SOMatrix__
#define __GDC1__SOMatrix__
#ifdef __cplus
#include <iostream>
#endif
int print_m();
#endif /* defined(__GDC1__SOMatrix__) */
And here is a partial listing of the SOMatrix.mm file
#include "SOMatrix.h"
#include <iostream>
using namespace std;
int print_m() {
// logic removed to keep it short; no compile time error
return 0;
}
When I build the project I got a linker error:
Undefined symbols for architecture x86_64:
"_print_m", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't understand why the function is showhow changed to have a leading underscore in the name ('_print_m').
Why this error occurs? Do I need to add the .mm file explicitly to the project?
You need to change these lines:
#ifdef __cplus
#include <iostream>
#endif
to this in your .h file:
#ifdef __cplusplus
#include <iostream>
extern "C"
{
#endif
with a companion:
#ifdef __cplusplus
}
#endif
at the end of the .h file.
Because you are trying to access a C++ function from Objective-C, and C++ tends to do a bit of name mangling (adding the underscore, for example). Adding the "extern "C"" bit allows your Objective-C code to find your C function declarations. The answers to this related question might elaborate on things a bit better than I can.

Bison %code top error

%code top command doesn't include its contents in parser.tab.h file (It should do so, right?). Bison version is 2.4.1. What is the problem with this (simplified) code?
%{
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <io.h>
#define YYDEBUG 0
int errors;
%}
%code top {
struct DICT
{
char *Name;
int Offs;
int Size;
struct DICT *Next;
};
typedef struct DICT DICT;
struct NODE
{
int ID;
int Value;
DICT *Var;
struct NODE *Left;
struct NODE *Right;
};
typedef struct NODE NODE;
}
%{
NODE *Tree = 0;
NODE *Node(int ID, int Value, DICT *Var, NODE *Left, NODE *Right);
void yyerror(char *s)
{
errors++;
printf("%s\n", s);
}
%}
%no_lines
%union
{
int Value;
char *ID;
NODE *Node;
}
EDIT:
with "%code requires" problem was resolved but another arise:
parser.tab.h:40: error: redefinition of 'struct DICT'
parser.tab.h:47: error: redefinition of typedef 'DICT'
parser.tab.c:145: error: previous declaration of 'DICT' was here
Using %code top will not insert the code into the header but only into the source file. It is well documented here.
I guess %code provides (or %code requires) will be more suited because it inserts the definitions in both source and header file.