Create dll using Perceptual SDK - dll

Good day!
I runned exapmles MyFirstDll and FaceAnalysis. They work fine and now i want to create dll with PSDK functionality.
PercDll.cpp:
extern "C++" CALLBACKPROC_API void Start(void)
{
MainCore* core_ = new MainCore();
core_->ToGo();
}
MainCore.h:
class MainCore
{
public:
MainCore() { }
int ToGo()
{
UtilPipeline* pipeline = new UtilPipeline(); /* 1 */
return 0;
}
};
If i commit string /* 1 / all builds and works fine. But when i uncommit string / 1 */ i look errors:
Error 1 error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all#_Container_base12#std##QAEXXZ) already defined in libpxcutils_d.lib(util_pipeline_raw.obj) c:\Users\i\documents\visual studio 2010\Projects\Perceptual10\Perceptual10\msvcprtd.lib(MSVCP100D.dll)
Error 2 error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12#std##QAE#XZ)already defined in libpxcutils_d.lib(util_pipeline_raw.obj) c:\Users\i\documents\visual studio 2010\Projects\Perceptual10\Perceptual10\msvcprtd.lib(MSVCP100D.dll)
Error 4 error LNK1169: one or more multiply defined symbols found c:\users\i\documents\visual studio 2010\Projects\Perceptual10\Debug\Perceptual10.dll 1
What's this? I am searching the solutio​n for a long time. Help please to fix it.
Thank you!

Related

unresolved symbol pthread_create, first referenced in ./armrtk/src/task.obj

I have been trying to figure this out for a few days now and cannot figure it out. I am using CCS as the IDE and I am working on windows. I am trying to create an RTOS Kernel on a MSP432 and need to use pthreads. I have been able to use pthreads in other examples but I am trying to do my own program and I get this issue when building :
unresolved symbol pthread_create, first referenced in ./armrtk/src/task.obj
I have included the file path into CCS and I cannot use a .cfg file because I am not using XDCTools. I just need help with this and I greatly appreciate it.
I also get a warning:
in pthread_create in TASK.C: #169-D argument of type "void *" is incompatible with parameter of type "void *(*)(void *)"
TASK.H
#ifndef TASK_H
#define TASK_H
#include <pthread.h>
struct task_t {
pthread_t* thread;
int threadCheck;
int state;
};
void *task1(void);
void *task2(void);
struct task_t *create_task(void* functionptr);
void delete_task(void *task);
#endif
TASK.C
#include <task.h>
#include <stdlib.h>
#include <pthread.h>
#define BLOCKED -1
#define READY 0
#define RUNNING 1
int testValue1 = 0;
int testValue2 = 0;
struct task_t *new_task;
pthread_t pntr;
struct task_t *create_task(void* functionptr) {
new_task = malloc(sizeof(struct task_t));
if(!new_task)
return NULL;
//set State of the new thread to ready
new_task->state = 0;
// check to see if pthread is created
**new_task->threadCheck = pthread_create(new_task->thread, NULL, functionptr, NULL);**
if(new_task->threadCheck!= 0){
//thread failed
return NULL;
}
return new_task;
}
void delete_task(void *task) {
if(task != NULL){
free(task);
pthread_exit(NULL);
}
}
The unresolved symbol error is a linker error, not a compiler error. You have failed to link the pthreads library.
With respect to the warning functionptr is a void* where pthread_create() expects a pointer-to-function with signature void fn(void*).
Your task functions have a different signature in any case: void fn(void), so in any event you will need to cast the function pointer in the call to pthread_create() (although you are loosing a useful means of passing information into a task function by omiting the void* argument).
Modify task.h:
typedef void* (*task_t)(void);
struct task_t *create_task( task_t functionptr);
The in task.cpp
new_task->threadCheck = pthread_create( new_task->thread,
NULL,
(void (*)(void *))functionptr,
NULL ) ;
The cast in the pthread_create() call alone would supress the warning, but it bad form to pass a function pointer as a generic void* since it would prevent the compiler warning you if you were to pass anything other then a function pointer of the expected form to to the create_task()`

ASSERT_THROW: error: void value not ignored as it ought to be

I am beginner to gtest. I trying to use ASSERT_THROW will compilation fail. Could anyone help on this:
class my_exp {};
int main(int argc, char *argv[])
{
EXPECT_THROW(throw my_exp(), my_exp); // this will pass
// This will through below compilation error
ASSERT_THROW(throw my_exp(), my_exp);
return 0;
}
Compilation output:
ERROR :
In file included from /usr/include/gtest/gtest.h:57:0,
from gtest.cpp:1:
gtest.cpp: In function ‘int main(int, char**)’:
gtest.cpp:12:3: error: void value not ignored as it ought to be
ASSERT_THROW(throw my_exp(), my_exp);
^
Short version
You write test in the wrong way, to write test you should put assertion inside test (macro TEST) or test fixtures (macro TEST_F).
Long version
1 . What's really happens?
To find out the real problem is not easy because the Google Testing Framework use macros which hide real code. To see code after macro substitution is required to perform preprocessing, something like this:
g++ -E main.cpp -o main.p
The result of preprocessing when using ASSERT_THROW will be looks like this (after formatting):
class my_exp {};
int main(int argc, char *argv[])
{
switch (0)
case 0:
default:
if (::testing::internal::ConstCharPtr gtest_msg = "") {
bool gtest_caught_expected = false;
try {
if (::testing::internal::AlwaysTrue () ) {
throw my_exp ();
};
} catch (my_exp const &) {
gtest_caught_expected = true;
} catch (...) {
gtest_msg.value = "Expected: throw my_exp() throws an exception of type my_exp.\n Actual: it throws a different type.";
goto gtest_label_testthrow_7;
} if (!gtest_caught_expected) {
gtest_msg.value = "Expected: throw my_exp() throws an exception of type my_exp.\n Actual: it throws nothing.";
goto gtest_label_testthrow_7;
}
}
else
gtest_label_testthrow_7:
return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "main.cpp", 7, gtest_msg.value) = ::testing::Message ();
return 0;
}
For EXPECT_THROW result will be the same except some difference:
else
gtest_label_testthrow_7:
::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "main.cpp", 7, gtest_msg.value) = ::testing::Message ();
2 . OK, the reason of different behaviour is found, let's continue.
In the file src/gtest.cc can be found AssertHelper class declaration including assignment operator which return void:
void AssertHelper::operator=(const Message& message) const
So now reason of the compiler complain is clarified.
3 . But why this problem is caused is not clear. Try realise why for ASSERT_THROW and EXPECT_THROW different code was generated. The answer is the macro from file include/gtest/internal/gtest-internal.h
#define GTEST_FATAL_FAILURE_(message) \
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
#define GTEST_NONFATAL_FAILURE_(message) \
GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
which contain return for fatal case.
4 . But now is question why this assertions usually works well?
To answer of this question try investigate code snipped which written in correct way when assertion is placed inside test:
#include <gtest/gtest.h>
class my_exp {};
TEST (MyExp, ThrowMyExp)
{
ASSERT_THROW (throw my_exp (), my_exp);
}
To exclude pollution of the answer I just notice that in such case the return statement for ASSERT_THROW also exist, but it is placed inside method:
void MyExp_ThrowMyExp_Test::TestBody ()
which return void! But in your example assertions are placed inside main function which return int. Looks like this is source of problem!
Try prove this point with simple snippet:
void f1 () {};
void f2 () {return f1();};
//int f2 () {return f1();}; // error here!
int main (int argc, char * argv [])
{
f2;
return 0;
}
5 . So the final answer is: the ASSERT_THROW macro contain return statement for expression which evaluates to void and when such expression is placed into function which return non void value the gcc complain about error.
P.S. But anyway I have no idea why for one case return is used but for other case is not.
Update: I've asked this question on GitHub and got the following answer:
ASSERT_XXX is used as a poor man's exception to allow it to work in
environments where exceptions are disabled. It does a return; instead.
It is meant to be used from within the TEST() methods, which return
void.
Update: I've just realised that this question described in the official documentation:
By placing it in a non-void function you'll get a confusing compile error > like "error: void value not ignored as it ought to be".

How to cast Int to unsigned short in Swift

I have the following function from the Objective-C library in Swift project:
- (DDHotKey *)registerHotKeyWithKeyCode:(unsigned short)keyCode modifierFlags:(NSUInteger)flags task:(DDHotKeyTask)task {
// ...
}
I'm trying to call this function from Swift via the following code:
hotKeyCenter.registerHotKeyWithKeyCode(
kVK_ANSI_V,
modifierFlags: NSEventModifierFlags.ControlKeyMask.rawValue,
task: { _ in
// ...
}
)
Unfortunately, it gives me the following error:
Missing argument for parameter 'action' in call
However, if I change kVK_ANSI_V to any number like this
hotKeyCenter.registerHotKeyWithKeyCode(
34,
modifierFlags: NSEventModifierFlags.ControlKeyMask.rawValue,
task: { _ in
// ...
}
)
code compiles without any error.
As you know, kVK_ANSI_V defined in the Carbon framework:
var kVK_ANSI_V: Int { get }
As you see, it has an Int type while keyCode parameter of the method has an unsigned short type.
How can I cast Int to unsigned short? Is there any way to fix this error?
Thanks in advance.
You can create an UInt16 from any integer n simply
with UInt16(n). In your case:
hotKeyCenter.registerHotKeyWithKeyCode(
UInt16(kVK_ANSI_V),
modifierFlags: NSEventModifierFlags.ControlKeyMask.rawValue,
task: { _ -> Void in
})

PHP Extension return structure

I am working on a PHP extension and wants to let PHP returns a structure. But it always cause core dump. My step is:
./ext_skel --extname=test
./configure --enable-test
in php_test.h, add:
typedef struct mydata {
int m_id;
int m_age;
}MYDATA;
PHP_FUNCTION(wrap_getMydata);`
In test.c, add:
#define MY_RES_NAME "my_resource";
static int my_resource_descriptor;
PHP_FE(wrap_getMydata, NULL)
...
ZEND_MINIT_FUNCTION(test)
{
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
resid = zend_register_list_destructors_ex(NULL, NULL, MY_RES_NAME, module_number);
return SUCCESS;
}
PHP_FUNCTION(test_getMydata)
{
zval* res;
long int a, b;
long int result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &a, &b) == FAILURE) {
return;
}
MYDATA objData;
objData.m_id = a;
objData.m_age = b;
ZEND_REGISTER_RESOURCE(res, &objData, resid);
RETURN_RESOURCE(res);
}
add: var_dump(test_getMydata(3,4)) in test.php
then make; make install; ./php test.php, it prints:
Functions available in the test extension:
confirm_wrap_compiled
test_getMydata
Congratulations! You have successfully modified ext/wrap/config.m4. Module wrap is now compiled into PHP.
Segmentation fault (core dumped)
$ gdb ../../bin/php core.23310
Loaded symbols for /home/user1/php/php-5.2.17/lib/php/extensions/no-debug-non-zts-20060613/test.so
#0 0x00000000006388ad in execute (op_array=0x2a9569bd68) at /home/user1/php/php-5.2.17/Zend/zend_vm_execute.h:92
92 if (EX(opline)->handler(&execute_data TSRMLS_CC) > 0) {`
Can someone give some help?
sorry for the bad formatting in the comment - here is my final answer:
i had to rename the extension from test enter code hereto hjtest - everthing else should be pretty much in line with your posted sample.
tl;dr - the problem - and SIGSEGV in your sample is that you are registering a resource to a local variable objData - wich at the end of the function is not reachable anymore - you need to use emalloc to get a piece of dynamic memory - wich holds your MYDATA
as from there you have a resource - bound to some piece of dyn. memory, you need to register a dtor function - so you can release/efree your registered memory.
hope that helps.
to solve the above issue - modifie your resource registration like this:
MYDATA * objData=emalloc(sizeof(MYDATA));
objData->m_id = a;
objData->m_age = b;
ZEND_REGISTER_RESOURCE(return_value, objData, resid);
and add a dtor:
... MINIT
resid = zend_register_list_destructors_ex(resdtor, NULL, MY_RES_NAME, module_number);
and
static void resdtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
MYDATA *res = (MYDATA*)rsrc->ptr;
if (res) {
efree(res);
}
}
for full sample see this GIST: https://gist.github.com/hjanuschka/3ed54e66f017a379cf25

C++ CLI Class problem

----- hello, world 2.cpp -----
// Hello, World 2.cpp : main project file.
#include "stdafx.h"
#include "hello.h"
#include <string>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
hello hi = new hello("Bob", "Blacksmith");
Console::WriteLine(L"Hello, " + hi.getName + "!");
return 0;
}
----- hello.h -----
#include <string>
using namespace std;
#ifndef HELLO_H
#define HELLO_H
class hello
{
private:
string _fname;
string _lname;
//hello() { } // private default constructor
public:
hello(string fname, string lname);
void SetName(string fname, string lname);
string GetName();
};
#endif
----- hello.cpp -----
#include "stdafx.h"
#include "hello.h"
#include <string>
using namespace std;
hello::hello(string fname, string lname)
{
SetName(fname, lname);
}
void hello::SetName(string fname, string lname)
{
_fname = fname;
_lname = lname;
}
string hello::getName()
{
return _fname + _lname;
}
----- The errors -----
------ Build started: Project: Hello, World 2, Configuration: Debug Win32 ------
Hello, World 2.cpp
Hello, World 2.cpp(12): error C2440: 'initializing' : cannot convert from 'hello *' to 'hello'
No constructor could take the source type, or constructor overload resolution was ambiguous
Hello, World 2.cpp(13): error C2039: 'getName' : is not a member of 'hello'
\documents\visual studio 2010\projects\cpp\hello, world 2\hello, world 2\hello.h(8) : see declaration of 'hello'
hello.cpp
hello.cpp(17): error C2039: 'getName' : is not a member of 'hello'
\documents\visual studio 2010\projects\cpp\hello, world 2\hello, world 2\hello.h(8) : see declaration of 'hello'
hello.cpp(19): error C2065: '_fname' : undeclared identifier
hello.cpp(19): error C2065: '_lname' : undeclared identifier
Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Error messages tell you exactly where and what the problems are, though they can be a bit intimidating at first. Maybe I can help demystify them a bit:
Hello, World 2.cpp(12): error C2440: 'initializing' : cannot convert from 'hello *' to 'hello'
This means that on line 12 in Hello, World 2.cpp, you're trying to put a pointer to hello (the return from new) inside hi which is not a pointer type. Since you don't need a dynamically allocated object here, just drop the new.
In situations where you do need a dynamically allocated object, you would change the hi variable to hello * and add a corresponding delete.
Hello, World 2.cpp(13): error C2039: 'getName' : is not a member of 'hello'
C++ is case sensitive. In one file you have GetName, in the other you have getName. Pick one.
hello.cpp(19): error C2065: '_fname' : undeclared identifier
hello.cpp(19): error C2065: '_lname' : undeclared identifier
Line 19 of hello.cpp is the definition of the lower case getName. Since getName wasn't declared in the class (see previous error), the compiler has no idea what _fname or _lname are. These errors will go away once the original problems are solved.
Edit
See #Sergey's answer for some other more general observations of things to fix.
The new keyword creates a pointer - if you do it this way, 'hi' should be declared as hello*, or you should reqrite the declaration as:
hello hi(...);
The second error is just due to case sensitivity (getName, GetName).
hello hi = new hello("William", "Dyson");
Must be
hello* hi = new hello(...);
Or
hello hi("William", "Dyson"); ;
Console::WriteLine(L"Hello, " + hi.getName + "!");
Must be
Console::WriteLine(L"Hello, " + hi.getName() + "!");
There may be other failures but i have to go now.
There are several errors.
File names with whitespaces. Not critical, but can lead to problems
Console::WriteLine(L"Hello, " + hi.getName + "!");
this should be something like this:
string s("Hello, ");
s += hi->getName();
s += "!"
Console::WriteLine(s);
delete objects allocated with new: delete hi;
string hello::getName() should be string hello::GetName()
Never use the use namespace ... in header files
Include other files within guard block
If you allocate something with new you have to call delete after you don't need it anymore.
In case you want to use the garbage collector the clean up for you you have to declare the class as ref class hello and then instantiate it with:
hello^ hi = gcnew hello(...);
Some comments that undoubtedly will be posted before I'm finished writing this:
Put you public members first
the namespace System implies Managed C++, if you don't know what that is and think you are using plain C++, please read about printf and std::cout.
The line
hello hi = new hello("William", "Dyson");
should read
hello hi("William", "Dyson"); or hello* hi = new hello("William", "Dyson");
The first creates an object on the stack (which will be automatically destructed as it goes out of scope. The second creates a pointer to an object on the heap, which you will have to delete before the pointer goes out of scope (after you've finished with it)
about hello::getName(): you have typos with regards to capitalization (getname vs getName) and it should be declared like this (in header and accordingly in the source file):
const string getName() const;
The first const is optional, but I like it that way, the last one lets you call this function from a const hello object, and tells the reader that the function does not modify the object.
You should pass string by reference (here is a correcter constructor):
hello( const string &fname, const string& lname);
Sources and headers should have names without spaces (or special characters) in them, this will be problematic for UNIX<->Windows if you're not careful.
That's all I can see right now.