I have built the LLVM using CMake using VS 2012 in keeping with documentation. I am trying to build a toy compiler with flex, bison and LLVM. The final stage of my compiler my main class looks like this:
#include <iostream>
#include "codegen.h"
#include "node.h"
#include "llvm/Target/Targetmachine.h"
using namespace std;
extern int yyparse();
extern NBlock* programBlock;
void createCoreFunctions(CodeGenContext& context);
int main(int argc, char **argv)
{
yyparse();
std::cout << programBlock << endl;
InitializeNativeTarget();
CodeGenContext context;
createCoreFunctions(context);
context.generateCode(*programBlock);
context.runCode();
return 0;
}
As stated in my previous post LLVM 3.4 linker errors in VS 2012. To workaround the solution I manually added the x86 files I was missing (taking clue from the errors). I ended up adding the following to the main:
#include "llvm-3.4/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h"
#include "llvm-3.4/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h"
#include "llvm-3.4/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h"
#include "X86MCAsmInfo.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/MC/MCInstrAnalysis.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MachineLocation.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetRegistry.h"
#include "X86GenRegisterInfo.inc"
#include "X86GenInstrInfo.inc"
#include "X86GenSubtargetInfo.inc"
But I noticed that the following are missing from my system:
"X86MCAsmInfo.h"
"X86GenRegisterInfo.inc"
"X86GenInstrInfo.inc"
"X86GenSubtargetInfo.inc"
I looked through the online documentation but I am a beginner on the topic, most of it did not make too much sense to me. I would appreciate if someone could guide me or point me to the right tutorial which gives me a better understanding of what I am doing wrong here.
Related
I'm writing a project in Vulkan and it compiles and runs fine. The code is the same as it always was, but after some software updates (Steam, Visual Studio, etc.) an error has been popping up.
I mention steam as that was causing a separate runtime error. The same error as here: https://www.reddit.com/r/vulkan/comments/8ybq6f/need_some_help_debugging/e29qptx/
Anyway, the line:
const std::vector<const char*> validationLayers = { "VK_LAYER_LUNARG_standard_validation" };
and ones like that using std::vector and std::array give me the error: Ambiguous symbol 'const std::vector<const char*>'
My includes and defines are as follows:
#define GLFW_INCLUDE_VULKAN
#define GLM_FORCE_RADIANS
#define STB_IMAGE_IMPLEMENTATION
#include <glfw3.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <stb/stb_image.h>
#include <iostream>
#include <stdexcept>
#include <functional>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <array>
#include <chrono>
#ifdef NDEBUG
const bool enableValidationLayers = false;
#else
const bool enableValidationLayers = true;
#endif
So if there's a way to suppress this particular error highlighting, or if there is a genuine conflict, I'd love to know where it is / how to do it.
Like I say, it still runs fine, but it is annoying to look at my scroll bar and see a bunch of red markers that would normally indicate my program not compiling.
This turned out to be an issue with the version of ReSharper I was using. It is also reported here: https://resharper-support.jetbrains.com/hc/en-us/community/posts/360000430159-Intellisense-issue-with-C-17-standard?flash_digest=bbcceaf4d5a9c12c634a59aba32fc2143a325734
The solution is to turn it off or upgrade to R++ 2018.2
I want to use ChatScript externally in my program. In the documents it says:
Embedding Step #1 First, you will need to modify `common.h and compile the system. You need to add all the CS .cpp files to your build list.
Find the // #define NOMAIN 1 and uncomment it. This will allow you to compile your program as the main program and ChatScript merely as a collection of routines to accompany it.
But I am newbie in Linux and can’t understand how to add .cpp files to my build list? What is my build list? May someone explains what do should I do exactly?
I did copy all the .cpp and .h and other folders existed inside ChatScript/SRC directory beside my main.cpp in my project.
Then I tried to run this code:
#include<iostream>
using namespace std;
char* output2;
unsigned int InitSystem(int argc,char* argv[],char* unchangedPath,char* readonlyPath,char* writablePath);
void InitStandalone();
void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);
int main()
{
PerformChat(NULL,NULL,"hi",NULL,output2);
cout<<output2;
return 0;
}
But I get this error message:
undefined reference to `PerformChat(char*, char*, char*, char*, char*)
Then I did include all the header files to my program and delete this line of code: void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);
#include<iostream>
#include "common.h"
#include "common1.h"
#include "constructCode.h"
#include "cs_ev.h"
#include "csocket.h"
#include "dictionaryMore.h"
#include "dictionarySystem.h"
#include "english.h"
#include "evserver.h"
#include "factSystem.h"
#include "functionExecute.h"
#include "infer.h"
#include "jsmn.h"
#include "json.h"
#include "mainSystem.h"
#include "markSystem.h"
#include "mongodb.h"
#include "mprintf.h"
#include "multi.h"
#include "my_sql.h"
#include "os.h"
#include "outputSystem.h"
#include "patternSystem.h"
#include "postgres.h"
#include "privatesrc.h"
#include "scriptCompile.h"
#include "spellcheck.h"
#include "systemVariables.h"
#include "tagger.h"
#include "testing.h"
#include "textUtilities.h"
#include "tokenSystem.h"
#include "topicSystem.h"
#include "userCache.h"
#include "userSystem.h"
#include "variableSystem.h"
using namespace std;
char* output2;
unsigned int InitSystem(int argc,char* argv[],char* unchangedPath,char* readonlyPath,char* writablePath);
void InitStandalone();
void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);
int main()
{
PerformChat(NULL,NULL,"hi",NULL,output2);
cout<<output2;
return 0;
}
But the new error says:
error: conflicting declaration of C function ‘int main()'
You would have to include all the chatscript SRC files in your project to get the function PerformChat to compile. But shortly ChatScript will release with library compilations as well.
I'm using Crypto++ to encrypt files in C++. And I'm using the code below.
It doesn't contain the headers files so I added my own :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <cryptopp/cryptlib.h>
#include <cryptopp/sha.h>
#include <cryptopp/secblock.h>
#include <cryptopp/files.h>
#include <cryptopp/queue.h>
#include <cryptopp/hex.h>
#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/osrng.h>
#include <cryptopp/integer.h>
#include <cryptopp/dh.h>
#include <cryptopp/sha.h>
#include <cryptopp/modes.h>
#include <cryptopp/eax.h>
#include <cryptopp/tea.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/pssr.h>
#include <cryptopp/rsa.h>
#include <cryptopp/nbtheory.h>
#include <cryptopp/eccrypto.h>
#include <cryptopp/oids.h>
#include <cryptopp/modes.h>
#include <cryptopp/gzip.h>
#include <cryptopp/blowfish.h>
#include <cryptopp/rsa.h>
#include <cryptopp/rng.h>
#include <cryptopp/cryptlib.h>
#include <cryptopp/filters.h>
#include <cryptopp/rdrand.h>
using namespace std;
using namespace CryptoPP;
But unfortunately the code doesn't work
Saying that the GlobalRNG is not declared !
error: ‘GlobalRNG’ was not declared in this scope
I googled and kept looking for a solution for 2 days i found that it's a bug and fixed but i'm having the latest version : 5.6.3 !
So i really don't know why this error is showing !
In the version 5.6.3 GlobalRNG is defined in the file validate.h, as:
// Functions that need a RNG; uses AES inf CFB mode with Seed.
CryptoPP::RandomNumberGenerator & GlobalRNG();
Just add this inclusion:
#include <cryptopp/validate.h>
to solve definition problem.
GloablaRNG is part of testing and bench-marking. It should not be part of the library proper (i.e., libcryptopp.a or libcryptopp.so). If your programs are complaining about a missing GloablaRNG, then the library was cross-contaminated with some of the testing and bench-marking gear.
These are the files used for testing and bench-marking. They should not be included in your build of the library or your project:
validate.h
bench.h
test.cpp
bench1.cpp, bench2.cpp
validat0.cpp, validat1.cpp, validat2.cpp, validat3.cpp
datatest.cpp, regtest.cpp, fipsalgt.cpp, dlltest.cpp
You are free to use a function called GlobalRNG(). Here's how its used in the library's test and bench-marking gear. But you might consider using an AutoSeededRandomPool instead. The AutoSeededRandomPool is a PGP-style generator, and its seeded from /dev/urandom, /dev/srandom, /dev/random or the Windows entropy pool.
Declaration in validate.h
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Test)
CryptoPP::RandomNumberGenerator & GlobalRNG();
NAMESPACE_END // Test
NAMESPACE_END // CryptoPP
Definition in test.cpp
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_BEGIN(Test)
ANONYMOUS_NAMESPACE_BEGIN
OFB_Mode<AES>::Encryption s_globalRNG;
NAMESPACE_END
RandomNumberGenerator & GlobalRNG()
{
return dynamic_cast<RandomNumberGenerator&>(s_globalRNG);
}
NAMESPACE_END // Test
NAMESPACE_END // CryptoPP
Seeding in test.cpp
// Don't do this in production because it creates a deterministic generator
OFB_Mode<AES>::Encryption& aesg = dynamic_cast<OFB_Mode<AES>::Encryption&>(Test::GlobalRNG());
aesg.SetKeyWithIV((byte *)seed.data(), 16, (byte *)seed.data());
A lot of folks have had this problem over the years. At Crypto++ 6.0, we moved GlobalRNG() into the Test namespace. Test is a new namespace, and we hope Test::GlobalRNG() will provide the signals that something is amiss in your library build or project configuration.
Also see Issue 379, Add Test namespace within CryptoPP namespace and Commit 73836e58a5f5c11c.
I'm attempting to use clang programatically to compile some C++ to an object file and I get the error "unable to interface with target machine" during the codegenaction. I'm wondering if I have missed some step or otherwise what the problem could be.
Below is the output of the program:
C:\Application\Debug>Application
Initializing targets
Targets initialized
clang -cc1 version 3.4 based upon LLVM 3.4svn default target i686-pc-win32
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\lib\gcc\mingw32\4.7.2\include\c++
c:\mingw\lib\gcc\mingw32\4.7.2\include\c++\mingw32
c:\mingw\lib\gcc\mingw32\4.7.2\include\c++\backward
c:\mingw\lib\gcc\mingw32\4.7.2\include
c:\mingw\include
c:\mingw\lib\gcc\mingw32\4.7.2\include-fixed
End of search list.
error: unable to interface with target machine
1 error generated.
Here is my (very simple) program:
#include <string>
#include <memory>
#include <iostream>
#include <limits.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include "clang/CodeGen/CodeGenAction.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/system_error.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include <Windows.h>
using namespace std;
using namespace llvm;
using namespace clang;
using namespace clang::driver;
int main(int argc, const char **argv, char * const *envp) {
llvm::InitializeNativeTarget();
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
TextDiagnosticPrinter *DiagClient =
new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
driver::ArgStringList CCArgs;
CCArgs.push_back("-cc1");
CCArgs.push_back("-triple");
CCArgs.push_back("i686-pc-win32");
CCArgs.push_back("-emit-obj");
CCArgs.push_back("-O3");
CCArgs.push_back("-nostdsysteminc");
CCArgs.push_back("-mrelax-all");
CCArgs.push_back("-disable-free");
CCArgs.push_back("-v");
CCArgs.push_back("-coverage-file");
CCArgs.push_back("test.o");
CCArgs.push_back("-main-file-name");
CCArgs.push_back("test.cpp");
CCArgs.push_back("-mrelocation-model");
CCArgs.push_back("static");
CCArgs.push_back("-mdisable-fp-elim");
CCArgs.push_back("-fmath-errno");
CCArgs.push_back("-masm-verbose");
CCArgs.push_back("-mconstructor-aliases");
CCArgs.push_back("-target-cpu");
CCArgs.push_back("pentium4");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\lib\\gcc\\mingw32\\4.7.2\\include\\c++");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\lib\\gcc\\mingw32\\4.7.2\\include\\c++\\mingw32");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\lib\\gcc\\mingw32\\4.7.2\\include\\c++\\backward");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\lib\\gcc\\mingw32\\4.7.2\\include");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\include");
CCArgs.push_back("-internal-isystem");
CCArgs.push_back("c:\\mingw\\lib\\gcc\\mingw32\\4.7.2\\include-fixed");
CCArgs.push_back("-std=c++11");
CCArgs.push_back("-fdeprecated-macro");
CCArgs.push_back("-ferror-limit");
CCArgs.push_back("19");
CCArgs.push_back("-fmessage-length");
CCArgs.push_back("150");
CCArgs.push_back("-mstackrealign");
CCArgs.push_back("-fms-extensions");
CCArgs.push_back("-fmsc-version=1300");
CCArgs.push_back("-fobjc-runtime=gcc");
CCArgs.push_back("-fobjc-default-synthesize-properties");
CCArgs.push_back("-fcxx-exceptions");
CCArgs.push_back("-fexceptions");
CCArgs.push_back("-fdiagnostics-show-option");
CCArgs.push_back("-fcolor-diagnostics");
CCArgs.push_back("-backend-option");
CCArgs.push_back("-vectorize-loops");
CCArgs.push_back("-x");
CCArgs.push_back("c++");
CCArgs.push_back("-o");
CCArgs.push_back("test.o");
CCArgs.push_back("test.cpp");
OwningPtr<CompilerInvocation> CI(new CompilerInvocation);
CompilerInvocation::CreateFromArgs(*CI,
const_cast<const char **>(CCArgs.data()),
const_cast<const char **>(CCArgs.data()) +
CCArgs.size(),
Diags);
// Create a compiler instance to handle the actual work.
CompilerInstance Clang;
Clang.setInvocation(CI.take());
// Create the compilers actual diagnostics engine.
Clang.createDiagnostics();
if (!Clang.hasDiagnostics())
return 1;
OwningPtr<CodeGenAction> Act(new EmitObjAction());
if (!Clang.ExecuteAction(*Act))
return 1;
return 0;
}
I'm completely new to C++, but I have created a minor program, looking to port the program to other computers, but when I "install" the program I get this error...-static-libgcc -static-libstdc++ missing, is there a file I should be including in the program itself, or is this a library I have to install on each computer? The computers that I expect to run the program will be windows xp. Source code of the file is as follows:
#include <stdlib.h>
#include <windows.h>
#include <direct.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
_chdir("C:\\Program Files\\NCHSoftware\\Talk\\");
string number = "start talk.exe -dial " + std::string(argv[1]+4);
system(number.c_str());
exit;
return 0;
}
They are shared lib's that would need to be on the host computer.
To learn how to compile a static version;
See here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
Read the "-static-libgcc" & "-static-libstdc++" sections.