How to access Form components from cpp file - winforms

I am working with windows form application. I am having one form i.e Form1.h. In this form I have one pictureBox named pictureBox1. And I have one main.cpp file in which I want to access pictureBox1 of the Form1.h and display some Image from main.cpp file.
For doing this I am using this code
main.cpp
#include "Form1.h"
using namespace PUMA_LED_TESTER;
Form1^ form1=gcnew Form1;
form1->pictureBox1->Image =bmp;
But this code is giving error
error C3145: 'form1' : global or static variable may not have managed type 'PUMA_LED_TESTER::Form1 ^'
may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
I don't know why this error is coming. Can any body please tell me the solution for this error.
Thanks in Advance

Related

Getting undefined reference to `hmac_sha1' in C

This is my current workspace. I have the Headers in the same folder with the otp.c but whenever I compile and run it it returns an error telling me that hmac-sha1 is undefined. Hope someone can help me.
Short Background
Including a header file enables you to compile the source file into an object file by declaring the function.
However, to get an executable, you need to link the object files together whereby one function used in one object file may be defined (i.e. implemented) in another object file. When listing the objects for the linker, they must be arranged in order of dependency, e.g if a depends on b the a should appear before b on the command line (in case of circular dependencies please find a post on it).
Solution
The way you run gcc makes it first compile the sources into object files and link them. otp.c requires the function hmac_sha1 is probably in hmac-sha1.c (I am guessing from the header file name) and so you should run:
gcc otp.c hmac-sha1.c -o otp
Note that otp.c depends on hmac-sha1.c hence the order.

Include Files in Segger Embedded Studio

I am just starting out with Segger Embedded Studio. Right now trying to call a function of a included header file. The file seems to be included since it shows up in the dependencies. For now I simply included the header and C-File in the project directory.
The included Header- and C-Files are simply:
//##### Header-File ######
#ifndef TEST_H_
#define TEST_H_
void printText(void);
#endif //TEST_H_
and:
//###### C-File #########
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
void printText(void)
{
printf("Hello");
}
But when I try to call the printText Function in my main I get the error:
"Undefined Symbol: printText".
Why is the function not recognized?
"Undefined symbol" is a linker error. You are not linking the object code containing the definition of printText().
It is not an issue with the header file; including a header file does not cause the associated code to be linked - that is just the declaration so the compiler knows what the interface looks like. It is the linker than combines the separately compiled object code to form a program. You have not told the linker to use the object code containing printText(), and you have not told your IDE project to compile it to generate that object code.
The project tree clearly shows that only main.c is included in your project; you need to add the C file containing printText() too.
The concept of separate compilation and linking is what you need to grasp here.
Thank you Clifford for your answer. You are right I had some miss-conceptions about which files will be linked while building the project. In the special case of segger embedded studio there are, as I know by now, two ways to reference extern files.
Adding the files to the sources files folder is straight forward, but must be done separately for each project you want to use the respective files.
For frequently used files it is beneficial to create a dedicated library solution. Such a library can then be imported to any solution by choosing "add existing project". This will add all files of the library to your current solution (and show them in the project-tree). Now click the tab project -> dependencies. Your library should show up here. By acitivating the check box the linker will compile the referenced project upon builing your solution, allowing for the usage of your library functions.
Adding and linking library-project to a current solution

Compiling sqlite amalgamation to get user authentication throws errors C2129 and C1083

I want to compile the sqlite amalgamation to create a database which is protected by a password via user authentication.
I followed this tutorial: https://www.sqlite.org/howtocompile.html
And also the documentation by SQLite for the user_authentication: https://www.sqlite.org/src/doc/trunk/ext/userauth/user-auth.txt
When I try to compile it without the extra compile-time option "-DSQLITE_USER_AUTHENTICATION" and without adding the other documents it works. When I try to compile it with I get the error C2129 at sqlite.c and error C1083 at userauth.c
In this directory are the following files:
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h
sqlite3userauth.h
userauth.c
cl -DSQLITE_USER_AUTHENTICATION shell.c sqlite3.c userauth.c -Fesqlite3.exe
Following output:
shell.c
sqlite3.c
sqlite3.c(222878): error C2129: static function 'void sqlite3CryptFunc(sqlite3_context *,int,sqlite3_value **)' declared but not defined
sqlite3.c(16263): note: see declaration of 'sqlite3CryptFunc'
userauth.c
userauth.c(26): fatal error C1083: Cannot open include file: 'sqliteInt.h': No such file or directory
Generating Code...
In case there is something like C#'s db.SetPassword("MyPW") available in c, that would be perfect!
I followed [...] the documentation by SQLite for the user_authentication: https://www.sqlite.org/src/doc/trunk/ext/userauth/user-auth.txt
Well no, it doesn't look like you did. Those docs say
Activate the user authentication logic by including the
ext/userauth/userauth.c source code file in the build and adding the
-DSQLITE_USER_AUTHENTICATION compile-time option. The ext/userauth/sqlite3userauth.h header file is available to
applications to define the interface.
When using the SQLite amalgamation, it is sufficient to append the
ext/userauth/userauth.c source file onto the end of the amalgamation.
You are using the amalgamation, so you should append [the contents of] userauth.c to the amalgamation. That is, copy its contents to the end of sqlite3.c. From your directory listing and command line, it appears that you are instead attempting to build it as a separate source file, to be linked to the main one at the end. That's not equivalent, and in particular, it differs with respect to the effect on the scope of static functions and variables, which is exactly what your compiler is complaining about.
It's unclear whether -DSQLITE_USER_AUTHENTICATION should also be used with the amalgamation. A literal reading of the SQLite docs suggests not, but I would be inclined to guess that it actually is required either way if you want to enable the feature.
The error about the missing header is a little concerning, and it is possible that you will see it again. If you do, it may be sufficient to simply remove or comment out the corresponding #include directive, as all the needed declarations from that header, which is among the main sources, should already be included in the amalgamation.

Qt Serial Port + Database [duplicate]

I added a class IcecastServer to my QT-project, added the header-file to the pro file and added some code. Everytime I compile it the following errors occur:
release/icecastserver.o:icecastserver.cpp:(.text+0x39): undefined reference to _imp___ZN10QTcpServerC1EP7QObject'
release/icecastserver.o:icecastserver.cpp:(.text+0x50): undefined reference toimpZN12QHostAddressC1ENS_14SpecialAddressE'
release/icecastserver.o:icecastserver.cpp:(.text+0x68): undefined reference to _imp___ZN10QTcpServer6listenERK12QHostAddresst'
release/icecastserver.o:icecastserver.cpp:(.text+0x73): undefined reference to_imp_ZN12QHostAddressD1Ev'
release/icecastserver.o:icecastserver.cpp:(.text+0x9d): undefined reference to _imp___ZNK10QTcpServer11errorStringEv'
release/icecastserver.o:icecastserver.cpp:(.text+0x3d4): undefined reference toimpZN12QHostAddressD1Ev'
release/icecastserver.o:icecastserver.cpp:(.text+0x4bd): undefined reference to _imp___ZN10QTcpServerC1EP7QObject'
release/icecastserver.o:icecastserver.cpp:(.text+0x4d4): undefined reference to_imp_ZN12QHostAddressC1ENS_14SpecialAddressE'
release/icecastserver.o:icecastserver.cpp:(.text+0x4ec): undefined reference to _imp___ZN10QTcpServer6listenERK12QHostAddresst'
release/icecastserver.o:icecastserver.cpp:(.text+0x4f7): undefined reference toimpZN12QHostAddressD1Ev'
release/icecastserver.o:icecastserver.cpp:(.text+0x521): undefined reference to _imp___ZNK10QTcpServer11errorStringEv'
release/icecastserver.o:icecastserver.cpp:(.text+0x858): undefined reference to_imp_ZN12QHostAddressD1Ev'
What am I doing wrong?
This is the header-file:
#ifndef ICECASTSERVER_H
#define ICECASTSERVER_H
#include <QObject>
QT_BEGIN_NAMESPACE
class QTcpServer;
QT_END_NAMESPACE
class IcecastServer : public QObject
{
Q_OBJECT
public:
explicit IcecastServer(QObject *parent = 0);
signals:
public slots:
private:
QTcpServer *tcpServer;
};
#endif // ICECASTSERVER_H
This is the source-file:
#include "icecastserver.h"
#include "QDebug"
#include <QtNetwork/QTcpServer>
#include <QtGui>
IcecastServer::IcecastServer(QObject *parent) :
QObject(parent)
{
tcpServer = new QTcpServer(this);
//tcpServer->listen(QHostAddress::Any,8000);
if (!tcpServer->listen()){
QMessageBox::critical(NULL, tr("Fortune Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString()));
return;
}
}
First you need to #include <QHostAddress> somewhere assuming that commented out line is what caused the problem.
You may also to check some project settings to see if you have all the correct inputs.
Edit: More detail
QtNetwork requires QT network lib inputs. Assuming once again that you are using QtCreator as not much info was provided then this means in your .pro file you need to have a line like so:
QT += network
Then make sure you include the right headers for the objects you are using before using them. If you still get undefined references, linking errors, etc try a QMake and rebuild. If it still persists you probably have errors in your code in addition to QT usage errors and should validate that your methods and objects being used were properly declared.
Final Edit: Glad that worked ...
When you create a new project in QTCreator there is a step in the wizard where you can check off the various QT libraries you want to include which will add these .pro lines and inputs for you. This is QT version of inputting additional lib files and by default they will be statically linked I believe. If you want to dynamically link with shared objects or dll then there is some extra configuration steps.
Are you running the moc tool over your header file? Are you subsequently compiling the output from the moc tool?

Error: L6218E: Undefined symbol main (referred from __rtentry2.o)

anyone can help me?? my board is LPC1768 and the sensor is BMP180
Rebuild target 'Target 1'
compiling BMP180.c...
compiling I2C.c...
assembling startup_LPC17xx.s...
compiling system_LPC17xx.c...
compiling GPIO_LPC17xx.c...
compiling PIN_LPC17xx.c...
linking...
.\Objects\asdsa.axf: Error: L6218E: Undefined symbol main (referred from __rtentry2.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
".\Objects\asdsa.axf" - 1 Error(s), 0 Warning(s).
Target not created.
I found the solution is easy, but before going deeper into the solution, keep in mind that C compilation unit (C Compiler and Assembler at least) compiles each pure C source file after resolving necessary pre-processor directives, and generates a relocatable object file as a result of compilation.
After the compilation unit does its job, there is another unit that is responsible for combining individually every source file that is compiled successfully into the relocatable form of one big object file for all. This unit is called Linker and the operation is called Linking
A very important feature in relocatable object file is that what is called variable, function will be noted as symbol so far. The linker has to solve the symbols, defining what is originally defined in an object file, reference what is being used in another to their original object file.
After this motivation, now we can call main() function as main() symbol.
I Found that the problem is because the source file that contains the main() function was not compiled. As a result, there is no a relocatable object file that contains the symbol corresponding to main() function. Hence, the compiler is complaining: you asked me to use (reference) a symbol you guaranteed to be found (defined) in another file but I found no such symbol!
The solution:
For Kiel IDE, to queue a source file for a compilation; you gotta shortlist it in the category "Source Group",by clicking right, either adding new files to group, or existing files to group. It will result in something like the following figure:
Now we have a main function, is turned (defined) to main symbol later, and found by the linker to reference it to whatever use it in any other relocatable object files.
I solved this problem with the following steps;
Delete your old project and create new project
Choose true library from Manage Run Time Environment like so:
Configure "Options for Target" segment. Define symbol USE_STDPERIPH_DRIVER and define project path like so:
Test your configuration. Please write the following code:
#include "stm32f10x.h" // Device header
int main() {
}
I had the same issue. The problem was that the function name in .c file had a different name with the one in the .h file, and I didn't know.
just add your c file (ex: 'main.c') to the source group (ex: 'source group 1') by expanding the target then right click on the source group, choose add existing files to group 'your source group', then choose the main.c file.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/14222.html
This should help.
Just create a dummy main() or main.c file. Linker can't find it in your pjt.
For solution only add this file C to driver folder and translate it,
Solved: This "Target Not Created" Issue was Resolved by the setting of Run Time Environment as shown in below(url) image.https://i.stack.imgur.com/kJ4IL.jpg ( consisting of CMSIS and Device supporting components in Run time environment)
{ compiling TransformFunctions.c...
linking...
Program Size: Code=768 RO-data=320 RW-data=4 ZI-data=612
FromELF: creating hex file...
".\Objects\LPC1768_B_T.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:07
}

Resources