LLVM metadata and external function error - llvm

I wrote the following code:
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"
using namespace llvm;
int main() {
int a=0,b=0,c=0;
Instruction *I;
LLVMContext& C = I->getContext();
MDNode* N = MDNode::get(C, MDString::get(C, "my md string content"));
I->setMetadata("my.md.name", N);
if(a>b){
c=a;
cast<MDString>(I->getMetadata("my.md.name")->getOperand(0))->getString();
}
else
c=b;
return c;
}
When I try to run this code with lli, it generates the following error:
"LLVM ERROR: unable to find external function '___ZXXcONTEXT4LS' that can't be resolved!"
Can you help me solve this problem? I'm aware about the LIBFFI project. Unfortunately, LIBFFI still has problems in running on windows platform. Is there any other solution to this?

There are at least two serious problems here:
I is not allocated before you redirect it (this can result in a segmentation fault).
What do you mean you "run this with lli"? lli should be used to interpret/JIT LLVM IR. What you have shown above is likely a C++ program that has to be linked with LLVM, and these are completely different things.
Did you try to go through the LLVM tutorial? It's highly recommended.

Related

Problem with WFDB library in C++ project (undefined reference)

I am trying to link PhysioBank data to my Qt program in Windows 7. I followed the instruction from PhysioNet website and WFDB programmer's guide to install the package in MinGW, and tried to link the library to a simple testing program as suggested in the guide (as below). However, problems show up no mater I try with either Qt creator or Dev C++.
As suggested in the guide (p. 9), I copied curl and wfdb folders and headers to the Visual C++ directory that contains "stdio.h", and include signal.c and wfdbio.c as source files. But eventually the Qt compile error message says that "inttype.h" is not found. I guessed this is because Qt uses Visual C++ compiler but not suggested gcc, and required headers are different. But when I turn to try with Dev C++, which uses gcc 4.9.2, other errors still show up, like: "undefined reference to _imp__curl_version". Is this because the compiler is still somewhat different from that used by MinGW? If my guess is right, how could my work be possibly done?
Sorry for any beginner's mistake. Thanks very much for kind reply!
#include <stdio.h>
#include <wfdb/wfdb.h>
int main(void)
{
int i;
WFDB_Sample v[2];
WFDB_Siginfo s[2];
if (isigopen("100s", s,2) < 2)
exit(1);
for (i = 1; i< 10; i++){
if (getvec(v) < 0)
break;
printf("%d\t%d\n",v[0],v[1]);
}
exit(0);
}

Code Blocks 16.01 can't find headers

code blocks 16.01 can't find headers.
I write some c++ code:
#include <iostream>
.....
int main()
{
...
}
it can be compiled without any errors or warnings, and run perfectly. But when I right-click the iostream then choose open iostream, it says that "Not found: iostream"
why? how to solve this problem?
I finally found that it's a matter of setting.
We should set the path of compiler as "...\codeblocks\MinGW\" rather than "...\codeblocks\MinGW\bin\". At meantime we should add an environment variable which is "...\codeblocks\MinGW\bin"
You're using int main function. In other words, it is waiting for a return of an integer. You can also solve this by just using void main function.

Fatal Error: error when reading "C:\OpenSSL-Win32\lib\libeay32.lib": unexpected end-of-file

i want to implement cryptographic algorithm to the arm at91sam7 micro. so i started with simple sha-1 openssl hash function. i could compile this sample code of sha-1 with code::block software and got true output. but when i want to use this code in my micro, i must compile and built it with arm compiler (for example IAR Workbench especially). i could compile the code in IAR truly but when i want to built it, i give no definitions errors. so i added C:\OpenSSL-Win32\lib\libeay32.lib to the linker additional library but i give this linker error:
'Fatal Error: error when reading "C:\OpenSSL-Win32\lib\libeay32.lib": unexpected end-of-file'.
could every one help me?Appreciate the help.
my sample code is:
#include <stdio.h>
#include <stdlib.h>
#include <openssl/evp.h>
int main (){
EVP_MD_CTX sha1ctx;
unsigned char sha1val[EVP_MAX_MD_SIZE];
unsigned int i, sha1len;
char buf[2]="80";
int numIn;
EVP_DigestInit(&sha1ctx, EVP_sha1());
numIn=2;
EVP_DigestUpdate(&sha1ctx, buf, numIn);
EVP_DigestFinal(&sha1ctx, sha1val, &sha1len);
printf("SHA1: ");
for(i=0; i<sha1len; i++)
printf("%02x", sha1val[i]);
printf("\n");
EVP_MD_CTX_cleanup(&sha1ctx);
return 0;
}
The library C:\OpenSSL-Win32\lib\libeay32.lib is probably for the wrong architecture. You are cross-compiling for an embedded system target (at91sam7), use the library for that target.

Why sizeof works well on linux and encounter a runtime error on windows

I wrote a simple program in c++:
#include<iostream>
using namespace std;
int main()
{
cout<<sizeof(bool)<<endl;
return 0;
}
but when I compiled it with minGW and run it on windows7,a messagebox comeout saying Application stop working.but when I compiled it on linux with g++,it works well.How could this happen?
when I use printf on windows it works fine.Could anyone please explain why?
Are you sure you have the latest C++ libraries? in the old one it is just check this out.
and i think the new library is std::cout<<"" so i think you are using the old library. Try <iostream.h>

mingw produces broken .exe

I have installed the newest MinGW suite. My project still compiles without any error but the produced executable is not working. Starting it results in the well known windows xp error message. Paradoxically source code like
#include <stdio.h>
int main()
{
printf("test\n");
return 0;
}
produces a working executable while
#include <iostream>
int main()
{
std::cout << "test\n" << std::endl;
return 0;
}
compiles fine but the executable is broken as described above.
Before i made the update everything worked. So what goes wrong here?
Do you have the libstdc++-*.dll in the path? It may be shared in newer MinGW versions, and std::cout uses it.
A tool like Process Monitor will probably tell you what is actually going wrong in more detail, and possibly even tell you what you need to fix to make it work.