want to add some Camera SDK in my swift project.. but cant solve this error..
libAndHeaders/MediaPlayer/G711Codec.h:42:1: error build: unknown type name 'class'; did you mean 'Class'?
maybe this is cpp header file or some other file. when i include this in my Objectice-c header file then it gives me this err..
/*
G711解码库
*/
#ifndef _G711_CODEC_H_
#define _G711_CODEC_H_
#define word16 short
#define word32 int
#define Word16 short
#define Word32 int
#define HI_VOICE_MAX_FRAME_SIZE (480+1) /* dont change it */
#define BIAS (0x84) /* Bias for linear code. */
#define CLIP 8159
#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
#define QUANT_MASK (0xf) /* Quantization field mask. */
#define NSEGS (8) /* Number of A-law segments. */
#define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */
static int seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF,
0x1FF, 0x3FF, 0x7FF, 0xFFF};
static int seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF,
0x3FF, 0x7FF, 0xFFF, 0x1FFF};
/* HISI_VOICE codec type */
/* Real-time transport protocol(RTP) */
#define G711_A 0x01 /* 64kbps G.711 A, see RFC3551.txt 4.5.14 PCMA */
#define G711_U 0x02 /* 64kbps G.711 U, see RFC3551.txt 4.5.14 PCMU */
#define G711_ORG_A 0x41 /* original version 64kbps G.711 A */
#define G711_ORG_U 0x42 /* original version 64kbps G.711 U */
typedef int (*G711_Decoder)(int sample);
class G711Codec
{
check this screenshot
Yes, it´s a c++ header. You can mix obj-c and c++ if you need to (such source files need to have .mm extension, so that the compiler recognizes them), but probably you can choose another (obj-c) framework for what you need.
Dear fellow programmers,
Currently I am working on implementing a Microsoft RPC server / client program on Windows. Using nmake, I managed to compile the client-side of the program, but the server-side gives some problems.
The following relevant files are:
Example1.idl
[
uuid(30f190d8-b966-4619-8f45-72342e6ad058),
version(1.0)
]
interface Example1
{
void Output(
[in, string] const char* szOutput
);
}
Example1.acf
[
implicit_handle(handle_t hExample1Binding)
]
interface Example1
{
}
Example1Server.cpp
#include <iostream>
#include "Example1.h"
void Output(
/* [string][in] */ const char* szOutput)
{
std::cout << szOutput << '\n';
}
RPC_STATUS CALLBACK SecurityCallback(RPC_IF_HANDLE, void*)
{
return RPC_S_OK;
}
int main()
{
RPC_STATUS status;
status = RpcServerUseProtseqEp(
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"),
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
reinterpret_cast<unsigned char*>("4747"),
NULL);
if (status) exit(status);
status = RpcServerRegisterIf2(
Example1_v1_0_s_ifspec,
NULL,
NULL,
RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
(unsigned)-1,
SecurityCallback);
if (status) exit(status);
status = RpcServerListen(
1,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
FALSE);
if (status) exit(status);
}
void* __RPC_USER midl_user_allocate(size_t size)
{
return malloc(size);
}
void __RPC_USER midl_user_free(void* p)
{
free(p);
}
makefile
!include <Win32.mak>
# all : Example1Client Example1Server
all : Example1Server
# # Make the client side application Example1Client. This works without compilation problems.
# Example1Client : Example1Client.exe
# Example1Client.exe : Example1Client.obj Example1_c.obj
# $(link) $(linkdebug) $(conflags) -out:Example1Client.exe \
# Example1Client.obj Example1_c.obj \
# rpcrt4.lib $(conlibs)
# # Example1Client main program
# Example1Client.obj : Example1Client.cpp Example1.h
# $(cc) $(cdebug) $(cflags) $(cvars) $*.cpp
# # Example1Client stub
# Example1_c.obj : Example1_c.c Example1.h
# $(cc) $(cdebug) $(cflags) $(cvars) $*.c
# Make the server side application Example1Server
Example1Server : Example1Server.exe
Example1Server.exe : Example1Server.obj Example1_s.obj
$(link) $(linkdebug) $(conflags) -out:Example1Server.exe \
Example1Server.obj Example1_s.obj \
rpcrt4.lib $(conlibsmt)
# Example1Server main program
Example1Server.obj : Example1Server.cpp Example1.h
$(cc) $(cdebug) $(cflags) $(cvarsmt) $*.cpp
# Example1Server stub file
Example1_s.obj : Example1_s.c Example1.h
$(cc) $(cdebug) $(cflags) $(cvarsmt) $*.c
# Stubs and header file from the IDL file
Example1.h Example1_c.c Example1_s.c : Example1.idl Example1.acf
midl Example1.idl
Here, Win32.mak is the windows32 file specifying generic settings for compiling with nmake on the Windows machine.
I ran the following commands (using the developer tools command prompt, Visual Studio 2015):
midl Example1.idl
Using the midl command, the header file Example1.h is generated, along with the stub files Example1_s.c and Example1_c.c.
Example1_s.c:
/* this ALWAYS GENERATED file contains the RPC server stubs */
/* File created by MIDL compiler version 8.01.0620 */
/* at Mon Jan 18 19:14:07 2038
*/
/* Compiler settings for Example1.idl:
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0620
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* ##MIDL_FILE_HEADING( ) */
#if defined(_M_AMD64)
#pragma warning( disable: 4049 ) /* more than 64k source lines */
#if _MSC_VER >= 1200
#pragma warning(push)
#endif
#pragma warning( disable: 4211 ) /* redefine extern to static */
#pragma warning( disable: 4232 ) /* dllimport identity*/
#pragma warning( disable: 4024 ) /* array to pointer mapping*/
#pragma warning( disable: 4100 ) /* unreferenced arguments in x86 call */
#pragma optimize("", off )
#include <string.h>
#include "Example1.h"
#define TYPE_FORMAT_STRING_SIZE 7
#define PROC_FORMAT_STRING_SIZE 33
#define EXPR_FORMAT_STRING_SIZE 1
#define TRANSMIT_AS_TABLE_SIZE 0
#define WIRE_MARSHAL_TABLE_SIZE 0
typedef struct _Example1_MIDL_TYPE_FORMAT_STRING
{
short Pad;
unsigned char Format[ TYPE_FORMAT_STRING_SIZE ];
} Example1_MIDL_TYPE_FORMAT_STRING;
typedef struct _Example1_MIDL_PROC_FORMAT_STRING
{
short Pad;
unsigned char Format[ PROC_FORMAT_STRING_SIZE ];
} Example1_MIDL_PROC_FORMAT_STRING;
typedef struct _Example1_MIDL_EXPR_FORMAT_STRING
{
long Pad;
unsigned char Format[ EXPR_FORMAT_STRING_SIZE ];
} Example1_MIDL_EXPR_FORMAT_STRING;
static const RPC_SYNTAX_IDENTIFIER _RpcTransferSyntax =
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}};
extern const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString;
extern const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString;
extern const Example1_MIDL_EXPR_FORMAT_STRING Example1__MIDL_ExprFormatString;
/* Standard interface: Example1, ver. 1.0,
GUID={0x30f190d8,0xb906,0x4699,{0x8f,0x45,0x72,0x33,0x2e,0x6a,0xd0,0x58}} */
extern const MIDL_SERVER_INFO Example1_ServerInfo;
extern const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable;
static const RPC_SERVER_INTERFACE Example1___RpcServerInterface =
{
sizeof(RPC_SERVER_INTERFACE),
{{0x30f190d8,0xb906,0x4699,{0x8f,0x45,0x72,0x33,0x2e,0x6a,0xd0,0x58}},{1,0}},
{{0x8A885D04,0x1CEB,0x11C9,{0x9F,0xE8,0x08,0x00,0x2B,0x10,0x48,0x60}},{2,0}},
(RPC_DISPATCH_TABLE*)&Example1_v1_0_DispatchTable,
0,
0,
0,
&Example1_ServerInfo,
0x04000000
};
RPC_IF_HANDLE Example1_v1_0_s_ifspec = (RPC_IF_HANDLE)& Example1___RpcServerInterface;
extern const MIDL_STUB_DESC Example1_StubDesc;
#if !defined(__RPC_WIN64__)
#error Invalid build platform for this stub.
#endif
#if !(TARGET_IS_NT50_OR_LATER)
#error You need Windows 2000 or later to run this stub because it uses these features:
#error /robust command line switch.
#error However, your C/C++ compilation flags indicate you intend to run this app on earlier systems.
#error This app will fail with the RPC_X_WRONG_STUB_VERSION error.
#endif
static const Example1_MIDL_PROC_FORMAT_STRING Example1__MIDL_ProcFormatString =
{
0,
{
/* Procedure Output */
0x32, /* FC_BIND_PRIMITIVE */
0x48, /* Old Flags: */
/* 2 */ NdrFcLong( 0x0 ), /* 0 */
/* 6 */ NdrFcShort( 0x0 ), /* 0 */
/* 8 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */
/* 10 */ NdrFcShort( 0x0 ), /* 0 */
/* 12 */ NdrFcShort( 0x0 ), /* 0 */
/* 14 */ 0x42, /* Oi2 Flags: clt must size, has ext, */
0x1, /* 1 */
/* 16 */ 0xa, /* 10 */
0x1, /* Ext Flags: new corr desc, */
/* 18 */ NdrFcShort( 0x0 ), /* 0 */
/* 20 */ NdrFcShort( 0x0 ), /* 0 */
/* 22 */ NdrFcShort( 0x0 ), /* 0 */
/* 24 */ NdrFcShort( 0x0 ), /* 0 */
/* Parameter szOutput */
/* 26 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */
/* 28 */ NdrFcShort( 0x0 ), /* x86 Stack size/offset = 0 */
/* 30 */ NdrFcShort( 0x4 ), /* Type Offset=4 */
0x0
}
};
static const Example1_MIDL_TYPE_FORMAT_STRING Example1__MIDL_TypeFormatString =
{
0,
{
NdrFcShort( 0x0 ), /* 0 */
/* 2 */
0x11, 0x8, /* FC_RP [simple_pointer] */
/* 4 */
0x22, /* FC_C_CSTRING */
0x5c, /* FC_PAD */
0x0
}
};
static const unsigned short Example1_FormatStringOffsetTable[] =
{
0
};
static const MIDL_STUB_DESC Example1_StubDesc =
{
(void *)& Example1___RpcServerInterface,
MIDL_user_allocate,
MIDL_user_free,
0,
0,
0,
0,
0,
Example1__MIDL_TypeFormatString.Format,
1, /* -error bounds_check flag */
0x50002, /* Ndr library version */
0,
0x801026c, /* MIDL Version 8.1.620 */
0,
0,
0, /* notify & notify_flag routine table */
0x1, /* MIDL flag */
0, /* cs routines */
0, /* proxy/server info */
0
};
static const RPC_DISPATCH_FUNCTION Example1_table[] =
{
NdrServerCall2,
0
};
static const RPC_DISPATCH_TABLE Example1_v1_0_DispatchTable =
{
1,
(RPC_DISPATCH_FUNCTION*)Example1_table
};
static const SERVER_ROUTINE Example1_ServerRoutineTable[] =
{
(SERVER_ROUTINE)Output
};
static const MIDL_SERVER_INFO Example1_ServerInfo =
{
&Example1_StubDesc,
Example1_ServerRoutineTable,
Example1__MIDL_ProcFormatString.Format,
Example1_FormatStringOffsetTable,
0,
0,
0,
0};
#if _MSC_VER >= 1200
#pragma warning(pop)
#endif
#endif /* defined(_M_AMD64)*/
Example1.h
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 8.01.0620 */
/* at Mon Jan 18 19:14:07 2038
*/
/* Compiler settings for Example1.idl:
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0620
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* ##MIDL_FILE_HEADING( ) */
#pragma warning( disable: 4049 ) /* more than 64k source lines */
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif /* __RPCNDR_H_VERSION__ */
#ifndef __Example1_h__
#define __Example1_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifdef __cplusplus
extern "C"{
#endif
#ifndef __Example1_INTERFACE_DEFINED__
#define __Example1_INTERFACE_DEFINED__
/* interface Example1 */
/* [implicit_handle][version][uuid] */
void Output(
/* [string][in] */ const unsigned char *szOutput);
extern handle_t hExample1Binding;
extern RPC_IF_HANDLE Example1_v1_0_c_ifspec;
extern RPC_IF_HANDLE Example1_v1_0_s_ifspec;
#endif /* __Example1_INTERFACE_DEFINED__ */
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif
Next, running nmake, the following error is displayed:
link /DEBUG /DEBUGTYPE:cv /INCREMENTAL:NO /NOLOGO -subsystem:console,5.0 -out:Example1Server.exe ExampleServer.obj Example1_s.obj rpcrt4.lib kernel32.lib ws2_32.lib mswsock.lib advapi32.lib
LINK : warning LNK4010: invalid subsytem version number 5.0; default subsystem version assumed
Example1_s.obj : error LNK2001: unresolved external symbol Output
Example1Server.exe : fatal error LNK1120: 1 unresolved externals
My understanding is that the Output function is not found in Example1_s.obj. This object file is created from Example1_s.c, which is generated automatically with the midl command.
I have tried various things, such as including the header file to the link to the Example1Server, modifying the output function such that it resembles the output function in the acf file and looking around on the internet for solutions.
Most solutions found to the problems on the internet were centered around including the rpcrt4.lib, which is sadly not the solution to my problem.
I'm quite stuck at the moment, and would really appreciate it if someone can help me out in solving the LNK2001 error. Thanks in advance.
The Output function's parameter keyword in the Example1Server.cpp should be same as function declaration in the MIDL generated header file Example1.h
unsigned is missing in your case.
It should be as below in Example1Server.cpp
void Output(
/* [string][in] */ const unsigned char *szOutput)
Please help. I know how to use CHARTEVENT_KEYDOWN to get the key pressed and to use that to program an action for the key. However, I would like to program extra shortcuts to make use of existing MT4 interface functions and cannot find the appropriate programming language for it. If you want to create a trendline in MT4, you can click on the trendline button which puts MT4 in trendline drawing mode. I want to be able to press "l" and then have my code put the platform in trendline drawing mode. Please can you point me to the appropriate command to put MT4 into trendline drawing mode?
You can use the WinAPI PostMessageW() function to do the task.
You can use #include <WinUser32.mqh> to import the WinAPI function descriptions.
Then you can use these commands to perform the task you need.
(For trendline #define MT4_WMCMD_TRENDLINE 33257)
Here you can find the commands
#define MT4_WMCMD_AUTOSCROLL 33017
#define MT4_WMCMD_BARS 33018
#define MT4_WMCMD_CANDLES 33019
/* 33020 unknown */
#define MT4_WMCMD_GRID 33021
#define MT4_WMCMD_LINE 33022
#define MT4_WMCMD_SHIFT 33023
#define MT4_WMCMD_VOLUMES 33024
#define MT4_WMCMD_ZOOM_IN 33025
#define MT4_WMCMD_ZOOM_OUT 33026
/* 33027-33047 unknown */
#define MT4_WMCMD_EXPERT_INPUTS 33048 /* Open expert Inputs dialog */
/* 33049 unknown */
#define MT4_WMCMD_REMOVE_EXPERT 33050 /* Remove expert advisor from chart */
/* 33051-33053 unknown */
#define MT4_WMCMD_SAVE_AS_PICTURE 33054
#define MT4_WMCMD_3_MONTHS 33057
#define MT4_WMCMD_ALL_HISTORY 33058
#define MT4_WMCMD_LAST_MONTH 33063
#define MT4_WMCMD_SAVE_Statement 33064
/* 33055-33133 unknown */
#define MT4_WMCMD_PERIOD_D1 33134
/* 33135 unknown */
#define MT4_WMCMD_PERIOD_H4 33136
#define MT4_WMCMD_PERIOD_M1 33137
#define MT4_WMCMD_PERIOD_M5 33138
#define MT4_WMCMD_PERIOD_M15 33139
#define MT4_WMCMD_PERIOD_M30 33140
#define MT4_WMCMD_PERIOD_W1 33141
/* 33142-33156 unknown */
#define MT4_WMCMD_PROPERTIES 33157 /* Chart Properties (F8) */
/* 33158-33176 apparently unused */
#define MT4_WMCMD_PERIOD_SEPARATE 33177 /* Show/hide period separators */
/* 33178-33196 unknown */
#define MT4_WMCMD_MOVE_RIGHT 33197 /* Move right (right/down arrow) */
#define MT4_WMCMD_MOVE_LEFT 33198 /* Move left (left/up arrow) */
/* 33199-33219 unknown */
#define MT4_WMCMD_SAVE_TEMPLATE 33220 /* Save template... */
/* 33221-33229 unknown */
#define MT4_WMCMD_33230 33230 /* Arrow Down */
#define MT4_WMCMD_33231 33231 /* Arrow Up */
#define MT4_WMCMD_33232 33232 /* icons-ticks */
#define MT4_WMCMD_MOUSE_CROSS 33233 /* crosshair */
#define MT4_WMCMD_MOUSE_CURSOR 33234 /* the cursor */
#define MT4_WMCMD_33235 33235 /* Box-cyclical Line */
#define MT4_WMCMD_33236 33236 /* equidistant channel */
#define MT4_WMCMD_33237 33237 /* Fibonacci lines */
#define MT4_WMCMD_33238 33238 /* Box-Fibonacci-arc */
#define MT4_WMCMD_33239 33239 /* Box-Fibonacci-fan */
#define MT4_WMCMD_33240 33240 /* Box Channels, Fibonacci */
#define MT4_WMCMD_33241 33241 /* Box-Gann-grid Hanna */
#define MT4_WMCMD_33242 33242 /* Box-Gann-line Hanna */
#define MT4_WMCMD_33243 33243 /* Box-Gann-fan Hanna */
#define MT4_WMCMD_HLINE 33244 /* horizontal line */
/* 33245 unknown */
#define MT4_WMCMD_33246 33246 /* Box Andrews pitchfork */
#define MT4_WMCMD_33247 33247 /* Box-shape-rectangle */
#define MT4_WMCMD_33248 33248 /* Box-channels-linear regression */
/* 33249-33250 apparently unused */
#define MT4_WMCMD_33251 33251 /* Box-icons-stop */
/* 33252 unknown */
#define MT4_WMCMD_33253 33253 /* text */
#define MT4_WMCMD_33254 33254 /* Box-icons-bad */
#define MT4_WMCMD_33255 33255 /* Box-icons-well */
#define MT4_WMCMD_33256 33256 /* Box-Fibonacci-time-zone */
#define MT4_WMCMD_TRENDLINE 33257 /* trend line */
#define MT4_WMCMD_33258 33258 /* Box-Line-trend line for the corner */
#define MT4_WMCMD_33259 33259 /* Box-figure-triangle */
#define MT4_WMCMD_VLINE 33260 /* Vertical Line */
#define MT4_WMCMD_LABEL 33261 /* text label */
/* 33262-33323 unknown */
#define MT4_WMCMD_UPDATE_DATA 33324 /* This doesn't cause experts start() to run */
/* 33325-33333 unknown */
#define MT4_WMCMD_PERIOD_MN1 33334 /* timeframe MN */
/* 33335-34299 unknown */
#define MT4_WMCMD_34300 34300 /* 34300-34699 custom indicators in alphabetical order */
#define MT4_WMCMD_34700 34700 /* Indicators-moving average of oscillator */
#define MT4_WMCMD_34701 34701 /* Indicators-accelerator oscillator */
#define MT4_WMCMD_34702 34702 /* Indicators-accumulation/distribution */
#define MT4_WMCMD_34703 34703 /* Indicators-alligator */
#define MT4_WMCMD_34704 34704 /* indicators-average directional movement index */
#define MT4_WMCMD_34705 34705 /* indicators-average true range */
#define MT4_WMCMD_34706 34706 /* Indicators-awesome oscillator */
#define MT4_WMCMD_34707 34707 /* Indicators-bears power */
#define MT4_WMCMD_34708 34708 /* indicator-bollinger bands */
#define MT4_WMCMD_34709 34709 /* Indicators-bulls power */
#define MT4_WMCMD_34710 34710 /* Indicators-commodity channel index */
#define MT4_WMCMD_34711 34711 /* Indicators-demarker */
#define MT4_WMCMD_34712 34712 /* Indicators-envelopes */
#define MT4_WMCMD_34713 34713 /* Indicators-force index */
#define MT4_WMCMD_34714 34714 /* Indicators-fractals */
#define MT4_WMCMD_34715 34715 /* Indicators-gator oscillator */
#define MT4_WMCMD_34716 34716 /* Indicators-ichimoku kinko hyo */
#define MT4_WMCMD_34717 34717 /* Indicators-macd */
#define MT4_WMCMD_34718 34718 /* indicators-market facilitation index */
#define MT4_WMCMD_34719 34719 /* Indicators-momentum */
#define MT4_WMCMD_34720 34720 /* indicators-money flow index */
#define MT4_WMCMD_34721 34721 /* indicators-moving averages */
#define MT4_WMCMD_34722 34722 /* Indicators-on balance volume */
#define MT4_WMCMD_34723 34723 /* Indicators-parabolic sar */
#define MT4_WMCMD_34724 34724 /* indicators-relative strength index */
#define MT4_WMCMD_34725 34725 /* indicators-relative vigor index */
#define MT4_WMCMD_34726 34726 /* Indicators-standard deviation */
#define MT4_WMCMD_34727 34727 /* Indicators-stochastic oscillator */
#define MT4_WMCMD_34728 34728 /* Indicators-volumes */
#define MT4_WMCMD_34729 34729 /* Indicators-william's percent range */
/* 34730-34799 unknown */
#define MT4_WMCMD_LOAD_TEMPLATE 34800 /* 34800-34899 load template in alphabetical order */
#define MT4_WMCMD_REMOVE_TEMPLATE 34900 /* 34900-34998 Remove Template in alph. order (conf. dialog) */
#define MT4_WMCMD_KILL_TEMPLATES 34999 /* remove *.tpl (confirmation dialog) */
/* 35000-35399 unknown */
#define MT4_WMCMD_PERIOD_H1 35400 /* timeframe H1 */
#define MT4_WMCMD_OBJECTS_LIST 35402 /* open objects list window */
#define MT4_WMCMD_ORDER_BUYLIMIT 35454 /* order buy limit */
#define MT4_WMCMD_ORDER_BUYSTOP 35455 /* order buy stop */
#define MT4_WMCMD_ORDER_SELLLIMIT 35456 /* order sell limit */
#define MT4_WMCMD_ORDER_SELLSTOP 35457 /* order sell stop */
#define MT4_WMCMD_ORDER_MARKET 35458 /* new order (F9) */
#define MT4_WMCMD_35464 35464 /* right price tag */
#define MT4_WMCMD_35511 35511 /* Graphic template-download template */
/* 35512-37011 unknown */
/* 37012-40000 not inspected */
#define MT4_WMCMD_57602 57602 /* close the current chart */
#define MT4_WMCMD_57603 57603 /* Save as (ascii/csv) */
#define MT4_WMCMD_57604 57604 /* Save as (ascii/csv) - apparently same */
#define MT4_WMCMD_PRINT_DIALOG 57607 /* Open Print... Dialog */
#define MT4_WMCMD_PRINT_DIRECT 57608 /* Print immediately */
#define MT4_WMCMD_PRINT_PREVIEW 57609 /* Open Print Preview dialog */
/* 57610-59675 unknown (re-checked up to 58011) */
/* 59675-... not inspected */
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm working on an implementation of an EST(Enrollment over Secure Transport)-client over CoAPs for the OpenThread stack. For this, i want to write a CSR (Certificate Signing Request) by using mbedTLS, which is part of the stack as a third party software. My problem now is that i get some "undefined reference" error from the linker when i build the code (i'm using GCC on an Ubuntu 18.04.2 LTS machine).
As there are multiple functions for which the error occurs, i will provide code for just one example. here is my source file:
openthread/src/core/crypto/ecp.cpp:
#include "ecp.hpp"
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/ecp.h>
#include <mbedtls/pk.h>
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/random.hpp"
#include "openthread/entropy.h"
#include "openthread/random_crypto.h"
namespace ot {
namespace Crypto {
#if OPENTHREAD_ENABLE_EST_CLIENT && OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
otError Ecp::KeyPairGeneration(const uint8_t *aPersonalSeed,
uint32_t aPersonalSeedLength,
uint8_t * aPrivateKey,
uint32_t * aPrivateKeyLength,
uint8_t * aPublicKey,
uint32_t * aPublicKeyLength)
{
otError error = OT_ERROR_NONE;
mbedtls_pk_context keypair;
OT_UNUSED_VARIABLE(aPersonalSeed);
OT_UNUSED_VARIABLE(aPersonalSeedLength);
mbedtls_pk_init(&keypair);
// Generate keypair
VerifyOrExit(mbedtls_pk_setup(&keypair, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)),
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_ecp_group_load(&mbedtls_pk_ec(keypair)->grp, MBEDTLS_ECP_DP_SECP256R1) == 0,
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_ecp_gen_keypair(&mbedtls_pk_ec(keypair)->grp, &mbedtls_pk_ec(keypair)->d,
&mbedtls_pk_ec(keypair)->Q, mbedtls_ctr_drbg_random,
Random::Crypto::MbedTlsContextGet()) == 0,
error = OT_ERROR_FAILED);
VerifyOrExit(mbedtls_pk_write_pubkey_pem(&keypair, (unsigned char*)aPublicKey,
*aPublicKeyLength) == 0,
error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(mbedtls_pk_write_key_pem(&keypair, (unsigned char*)aPrivateKey,
*aPrivateKeyLength) == 0,
error = OT_ERROR_INVALID_ARGS);
exit:
mbedtls_pk_free(&keypair);
return error;
}
#endif // OPENTHREAD_ENABLE_EST_CLIENT
} // namespace Crypto
} // namespace ot
my header file:
openthread/src/core/crypto/ecp.hpp
#ifndef ECP_HPP_
#define ECP_HPP_
#include "openthread-core-config.h"
#include <stdint.h>
#include <stdlib.h>
#include <openthread/error.h>
namespace ot {
namespace Crypto {
/**
* #addtogroup core-security
*
* #{
*
*/
/**
* This class implements elliptic curve key generation.
*
*/
class Ecp
{
public:
/**
* This method generate a Elliptic Curve key pair.
*
* #param[in] aPersonalSeed An additional seed for the entropy. Can be NULL.
* #param[in] aPersonalSeedLengh The length of the #p aPersonalSeed.
* #param[out] aPrivateKey An output buffer where the private key should be stored.
* #param[inout] aPrivateKeyLength The length of the #p aPrivateKey buffer.
* #param[out] aPublicKey An output buffer where the private key should be stored.
* #param[inout] aPublicKeyLength The length of the #p aPublicKey buffer.
*
* #retval OT_ERROR_NONE EC key pairs has been created successfully.
* OT_ERROR_NO_BUFS Key buffers are too small or mbedtls heap too small.
*/
static otError KeyPairGeneration(const uint8_t *aPersonalSeed,
uint32_t aPersonalSeedLength,
uint8_t * aPrivateKey,
uint32_t * aPrivateKeyLength,
uint8_t * aPublicKey,
uint32_t * aPublicKeyLength);
};
/**
* #}
*
*/
} // namespace Crypto
} // namespace ot
#endif // ECP_HPP_
The functions which cause the error are here mbedtls_pk_write_pubkey_pem and mbedtls_pk_write_key_pem.
Here is also a part of the console output:
Making all in apps
Making all in cli
CC ot_cli_ftd-main.o
CC ot_cli_mtd-main.o
CCLD ot-cli-ftd
CCLD ot-cli-mtd
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: ../../../src/core/libopenthread-mtd.a(libopenthread_mtd_a-ecp.o): in function `ot::Crypto::Ecp::KeyPairGeneration(unsigned char const*, unsigned long, unsigned char*, unsigned long*, unsigned char*, unsigned long*)':
/home/scnm/eclipse-workspace/openthread/examples/../src/core/crypto/ecp.cpp:79: undefined reference to `mbedtls_pk_write_pubkey_pem'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/scnm/eclipse-workspace/openthread/examples/../src/core/crypto/ecp.cpp:83: undefined reference to `mbedtls_pk_write_key_pem'
collect2: error: ld returned 1 exit status
Makefile:1249: recipe for target 'ot-cli-mtd' failed
make[5]: *** [ot-cli-mtd] Error 1
I first thougth it was because i was missing some #define to actually use these functions, but i compared it with other OpenThread code which uses mbedtls and i can't see what i did wrong. As far as i've understood it, i have to modify the "openthread/third_party/mbedtls/mbedtls-config.h" file so that these funtions are build, so this is what i did:
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <openthread/config.h>
#include <openthread/platform/logging.h>
#include <openthread/platform/memory.h>
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
#define MBEDTLS_AES_C
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CCM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CMAC_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_ECJPAKE_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_HAVE_ASM
#define MBEDTLS_HMAC_DRBG_C
#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
#define MBEDTLS_MD_C
#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA256_SMALLER
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
#define MBEDTLS_SSL_EXPORT_KEYS
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_PROTO_DTLS
#define MBEDTLS_SSL_TLS_C
#if OPENTHREAD_ENABLE_BORDER_AGENT || OPENTHREAD_ENABLE_COMMISSIONER || OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_SRV_C
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#if OPENTHREAD_ENABLE_EST_CLIENT
#define MBEDTLS_PEM_WRITE_C
#define MBEDTLS_PK_WRITE_C
#define MBEDTLS_X509_CSR_WRITE_C
#define MBEDTLS_X509_CREATE_C
#endif
#endif
#ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_BASE64_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
#endif
#if OPENTHREAD_ENABLE_ECDSA
#define MBEDTLS_BASE64_C
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#endif
#define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */
#define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */
#define MBEDTLS_ECP_MAX_BITS 256 /**< Maximum bit size of groups */
#define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */
#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
#define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
#else
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
#endif
#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE
#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */
#else
#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */
#endif
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
#if defined(MBEDTLS_USER_CONFIG_FILE)
#include MBEDTLS_USER_CONFIG_FILE
#endif
#if defined(MBEDTLS_ECP_ALT) && !defined(MBEDTLS_ECP_RESTARTABLE)
typedef void mbedtls_ecp_restart_ctx;
#endif
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */
It resolved the "not defined in this scope" errors i've had before, but instead i have now the above described errors.
Here is what i've edited in the common-switch file:
openthread/examples/common-switches.mk
ECDSA ?= 0
// my code begin
EST_CLIENT ?= 0
// my code end
JAM_DETECTION ?= 0
ifeq ($(ECDSA),1)
configure_OPTIONS += --enable-ecdsa
endif
// my code begin
ifeq ($(EST_CLIENT),1)
configure_OPTIONS += --enable-est-client --enable-application-coap-secure
endif
// my code end
ifeq ($(JAM_DETECTION),1)
configure_OPTIONS += --enable-jam-detection
endif
and her what i've added to configure:
openthread/configure.ac
#
# EST Client
#
AC_ARG_ENABLE(est_client,
[AS_HELP_STRING([--enable-est-client],[Enable EST client support #<:#default=no#:>#.])],
[
case "${enableval}" in
no|yes)
enable_est_client=${enableval}
;;
*)
AC_MSG_ERROR([Invalid value ${enable_est_client} for --enable-est-client])
;;
esac
],
[enable_est_client=no])
if test "$enable_est_client" = "yes"; then
OPENTHREAD_ENABLE_EST_CLIENT=1
else
OPENTHREAD_ENABLE_EST_CLIENT=0
fi
AC_SUBST(OPENTHREAD_ENABLE_EST_CLIENT)
AM_CONDITIONAL([OPENTHREAD_ENABLE_EST_CLIENT], [test "${enable_est_client}" = "yes"])
AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_EST_CLIENT],[${OPENTHREAD_ENABLE_EST_CLIENT}],[Define to 1 if you want to enable EST Client])
OpenThread DNS Client support : ${enable_dns_client}
// my code begin
OpenThread EST Client support : ${enable_est_client}
// my code end
OpenThread SNTP Client support : ${enable_sntp_client}
I've also edited the makefile:
openthread/src/core/Makefile.am
crypto/ecdsa.hpp \
crypto/ecp.hpp \
crypto/hmac_sha256.hpp \
crypto/ecdsa.cpp \
crypto/ecp.cpp \
crypto/hmac_sha256.cpp \
My build command is "make -f examples/Makefile-nrf52840 EST_CLIENT=1".
I think once this problem is solved, i can solve the others by myself as the root of the problem seems to be the same.
Thanks.
You have an error during the link, the symbol mbedtls_pk_write_pubkey_pem is not defined, that means you missed to specify the lib defining it. Looking on the web it seems you need to link with mbedcrypto, so add libmbedcrypto.a or -lmbedcrypto (and may be use the option -L to specify the path)
It seems you also use X509, if you have missing symbols *X509* link with mbedx509, so add libmbedx509.a or -lmbedx509 (and may be use the option -L to specify the path)
I am working on a large project in C++ that is proprietary, so I can't actually share the source code. I have most of the code compiled, but there is one function, in a particular file, that is giving me quite a bit of trouble.
I've created a simple example that shows what the problem is. We have:
WTPSHORT.H
#ifndef WTP_H
#define WTP_H 1
#define VERSION "Version 2.1"
#define DATE "Nov., 2001"
/* ANSI C header files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
/************ Data structures for Water Treatment Plant ***************/
struct Effluent { /****** Data Packet for All Unit Processes *******/
/* Operating data: */
double DegK; /* Temperature (Deg K) */
double Flow; /* Average flow (MGD) */
double Peak; /* Max hourly flow (MDG) */
/* Unit process counters: */
short cl2cnt; /* Number of times chlorine added. */
/* Measurable Water Quality Parameters: */
double pH; /* [H+]=pow(10,-pH) (-) */
/* More variable definitions go here */
double beta_br; /* Constant for chlorine to bromine reactivity ratio */
double time_step; /* Time step (hrs) */
}; /************ End of struct Effluent ************/
/*****************************************/
struct ProcessTrain { /* Control Structure for Process Train */
struct UnitProcess *head; /* First UnitProcess in ProcessTrain */
struct UnitProcess *null; /* Always NULL */
struct UnitProcess *tail; /* Last UnitProcess in ProcessTrain */
char file_name[120]; /* Full path and extension */
}; /*****************************************/
struct UnitProcess { /********** Treatment Process ***************/
struct UnitProcess *next; /* Double Linked list */
struct UnitProcess *prev; /* " " " */
short type; /* Defined unit process types */
short pad; /* Maintain 32 bit alinment of pointers */
union { /* Design and operating parameters: */
void *ptr;
struct Influent *influent;
struct Mechdbp *mechdbp; //FOR MECH MODEL
struct Alum *alum;
struct Gac *gac;
struct Filter *filter;
struct Basin *basin;
// struct Membrane *membrane;
struct Mfuf *mfuf;
struct Nf *nf;
struct Iron *iron;
struct chemical *chemical;
struct clo2 *clo2;
struct lime *lime;
/*struct WTP_effluent *wtp_effluent; No longer needed - WJS, 11/98 */
struct Avg_tap *avg_tap;
struct End_of_system *end_of_system;
} data;
struct Effluent eff;
};
struct Influent { /* Raw Water Data */
double pH; /* (-) */
double temp; /* Average temperature (C) */
double low_temp; /* Low temperature for disinfection (C) */
double toc; /* (mg/L) */
double uv254; /* (1/cm) */
double bromide; /* (mg/L) */
double alkalinity; /* (mg/L as CaCO3) */
double calcium; /* Calcium Hardness (mg/L as CaCO3) */
double hardness; /* Total Hardness (mg/L as CaCO3) */
double nh3; /* Ammonia (mg/L as N) */
double ntu; /* Turbidity */
double crypto_req; /* Crypto Log removal + Log Inact. required*/
double clo2_crypto_ct_mult; /* Multiplier */
double peak_flow; /* Peak Hourly Flow for disinfection (MGD) */
double avg_flow; /* Average Flow (MGD) */
int swflag; /* TRUE=Surface Water; FALSE=Ground Water */
// char *run_name;
};
void s1_s2_est(struct UnitProcess *unit);
/* define(s) for UnitProcess.type */
#define VACANT 0
#define INFLUENT 1
#define RAPID_MIX 2
#define SLOW_MIX 3
#define SETTLING_BASIN 4
#define FILTER 5
#define BASIN 6
#define CONTACT_TANK 7
#define CLEARWELL 8
#define O3_CONTACTOR 9
#define GAC 10
#define MFUF_UP 11
#define NF_UP 12
#endif
And then there are two source files in the project:
s1s2_est.c
/* s1s2_est.c -- December, 2000*/
#include "WTPSHORT.H"
void s1_s2_est(struct UnitProcess *unit)
{
double toc, uva, s1_0, s2h_0, s2star_0, s2t_0, s1_f, s2h_f, s2star_f, s2t_f, H;
struct Effluent *eff;
eff = &unit->eff;
/* Get these inputs */
toc = eff->TOC;
uva = eff->UV;
s1_0 = eff->s1;
s2h_0 = eff->s2h;
s2star_0 = eff->s2_star;
H = pow(10.0, -eff->pH);
s2t_0 = s2h_0 + s2star_0;
s1_f = s1_0;
s2t_f = s2t_0;
s2star_f = s2star_0;
s2h_f = s2h_0;
if(eff->s1_s2_estflag == 'C')
{
/* Safety check */
if (toc < 0.0) toc = 0.0;
if (uva < 0.0) uva = 0.0;
s1_f = 5.05 * pow(toc, 0.57) * pow(uva, 0.54);
s2t_f = 13.1 * pow(toc, 0.38) * pow(uva, 0.40);
/* No increases in the S values allowed */
if(s1_f > s1_0 ) s1_f = s1_0;
if(s2t_f > s2t_0) s2t_f = s2t_0;
/* Speciate S2 */
s2h_f = s2t_f * eff->k21r * H / (eff->k21f + eff->k21r * H);
s2star_f = s2t_f * eff->k21f / (eff->k21f + eff->k21r * H);
}
if(eff->s1_s2_estflag != 'C' && unit->type == INFLUENT)
{/* Speciate S2 in raw water*/
s2h_f = s2t_f * eff->k21r * H / (eff->k21f + eff->k21r * H);
s2star_f = s2t_f * eff->k21f / (eff->k21f + eff->k21r * H);
}
/* Update Effluent data structure */
eff->s1 = s1_f;
eff->s2h = s2h_f;
eff->s2_star = s2star_f;
}/* End subroutine "s1_s2_est()"*/
and then
main.cpp
#include <stdio.h>
#include "WTPSHORT.H"
int main(int argc, char **argv)
{
UnitProcess *myunit;
s1_s2_est(myunit);
printf("done\n");
return 0;
}
When compiling and linking I see this error:
C:\WINDOWS\system32\cmd.exe /C "C:/MinGW/bin/mingw32-make.exe -j8 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ simple - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/joka0958/Desktop/wtp/compiledwtp/simple'
C:/MinGW/bin/g++.exe -c "C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
C:/MinGW/bin/gcc.exe -c "C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/s1s2_est.c" -g -O0 -Wall -o ./Debug/s1s2_est.c.o -I. -I.
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp: In function 'int main(int, char**)':
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp:7:22: warning: 'myunit' is used uninitialized in this function [-Wuninitialized]
s1_s2_est(myunit);
^
C:/MinGW/bin/g++.exe -o ./Debug/simple #"simple.txt" -L.
./Debug/main.cpp.o: In function `main':
C:/Users/joka0958/Desktop/wtp/compiledwtp/simple/main.cpp:7: undefined reference to `s1_s2_est(UnitProcess*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: [Debug/simple] Error 1
mingw32-make.exe: [All] Error 2
simple.mk:78: recipe for target 'Debug/simple' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/joka0958/Desktop/wtp/compiledwtp/simple'
Makefile:4: recipe for target 'All' failed
2 errors, 1 warnings
So the question is: Why am I getting an undefined reference?
I realize this is one of those errors that probably masks another problem, but I have really exhausted all possibilities, in my mind, of what could be causing the problem. Note that this is part of a larger project where many other functions compile and link properly.
By the way I am using Codelite with the MinGW compiler on Windows 10.
I'm sorry for all the consternation this question caused. It turns out that there was C++-specific functions within this file, but because the file was named with a *.c, codelite defaulted to the C compiler to actually compile this particular source file. Once I changed the filename, the code compiled successfully. Thanks for all of your useful suggestions!