basic trouble making the nlohmann json library work in Visual Studio 19 - visual-studio-2019

I'm a neophyte. I know I'm doing something bonheaded. I've search this and other fora for the last day and I'm stuck. I'm trying to use nlohmann's json library. I'm getting over 200 error messages, most of which seem to be rooted in the fact that the compiler can't see the header references in the main json.hpp file, but can see the json.hpp file.
I've copied the nlohmann library contents into the source folder and this is the code at the moment:
#include <iostream>
#include "nlohmann\json.hpp"
using json = nlohmann::json;
int main()
{
std::cout << "Hello World!\n";
}
I'm trying to minimize the number of variables I have to chase.
VS is finding the json.hpp file (no squiggly underline once I finally spelled it right, and a bunch of stuff in solution explorer under json.hpp and nlohmann) It also seems to be seeing the subdirectories of nlohmann
the 'json' after nlohmann:: has a squiggly underline; the popup says: namespace 'nlohmann' has no member 'json'
the first 20 or so 211 (!) error messages are code E1696 'cannot open source file' pointing to apparent references from json.hpp an example is: "E1696 cannot open source file "nlohmann/adl_serializer.hpp" json5 C:\Users\Rich\source\repos\json5\json5\nlohmann\json.hpp"
I've added the 'nlohmann' directory to the include directories that the compiler looks for (Project|properties|C/C++|Additional Include Directories) - no change in error message count. Do I need to manually add all of the subdirectories?

I Think you maybe using an older version of c++ (older than c++11).
Try adding this flag to the command -std=c++11.

Related

Get the path to work on ChartApplyTemplate in MT4

After reading the material I could find and trying various solutions, I still cannot get the ChartApplyTemplate to work. The template is not applying to the chart being opened and the error I receive is 5002 - the file cannot be found.
Here is my code:
int iChartID = ChartOpen(sChartNameL,5); ChartApplyTemplate(iChartID,"C:\\Users\\Jean\\AppData\\Roaming\\MetaQuotes\\Terminal\\DA3C92B1779898CC0CACD726A655BECB\\Files\\ADX.tpl");
Print(GetLastError());
I have also tried:
int iChartID = ChartOpen(sChartNameL,5);
string sTerminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH);
ChartApplyTemplate(iChartID, sTerminalDataPath + "\\MQL4\\Files\\ADX.tpl");
I have tried to place the template in various directories. Files as stated above but I have also tried to insert a files subdirectory in the mql4\experts subdirectory and also tried to use the files subdirectory under the MQL4 subdirectory. I have also left the template in the default templates directory. I have tried these various locations as I believe Metatrader has a sandbox environment for where files may be accessed.
Please can you help me.
You are using the wrong variable type for your chart ID, it should be of type long. The code should read as an example.
long iChartID = ChartOpen("EURUSD",5); ChartApplyTemplate(iChartID,"Popular.tpl");
For the location of the template file, from the documentation:
if the backslash "" separator (written as "\") is placed at the beginning of the path, the template is searched for relative to the path _terminal_data_directory\MQL4,
if there is no backslash, the template is searched for relative to the executable EX4 file, in which ChartApplyTemplate() is called;
if a template is not found in the first two variants, the search is performed in the folder terminal_directory\Profiles\Templates.

Resource compilation error (Bad character in source input)

I have added text file with following content to the project:
1 24 "MyApplication.manifest"
In the same folder there is also MyApplication.manifest file which is XML - this one:
C++ Builder / Delphi 2010 application manifest template
After I attempt to build resource from RC I get error - Bad character in source input(1)
Any ideas why?
RT_MANIFEST value is 24, but I am unsure what 1 is supposed to be.
I managed to find the answer myself so no answer necessary. The problem was, as usual very obscure.
Turned out that the resource script file (.RC) I was using had an UTF-8 byte order mark in the file (0xEF,0xBB,0xBF) which was invisible to the text editor but resource compiler complained about it. After removing the BOM resource compiled correctly.
I don't think many people fall into this trap but at least if anyone else sees this error in resource compiler, you should examine if there is an UTF-8 BOM in your file by viewing HEX-dump of RC file because brcc32.exe resource compiler seems to have issues with that.

OpenCV header error (YAML)

Ok so I feel that I have finally successfully used the OpenCV libraries in my app, except for one thing...
My .yml files get generated correctly except the '%YAML:1.0' header at the top turns out like this '01%YAML:1.0'. The '01' infront of the header is causing this error (I think):
OpenCV Error: Parsing error (/var/mobile/Applications/53C6CBA3-15B7-436A-892B-2ECFA75B72CD/Library/DownloadedDescriptors/descriptors.yml(1): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /Users/Dash/Documents/SmartServices/AirLink/ProjectGhost/FairfaxNewsDemo/opencv-2.3.1/OpenCV-2.3.1/modules/core/src/persistence.cpp, line 2163
Anyone know how to solve this issue?
Ok after looking into it a bit further I dont think it's the headers problem. My file always gets generated with '01' at the start.
Hmm...this is embarrassing. But it turns out that I had a 'print' statement lingering in the php file that helps generate my .yaml file, causing 0 and 1 to be added to the beginning of the document.
This meant that my file didn't start with '%YAML:1.0' as expected but '01%YAML:1.0'

ILASM does not set FileVersion

I have an .il file which I can compile without any problems. I can strong name it and so without any issues. But I am not able to set the file version via the attribute as I would expect it. How can I set the FileVersion for an assembly when using ilasm?
If I do a round trip I get always a .res file which does contain only binary data which is not readable. What is inside this res file and can I edit it?
The code does not work
.assembly myAssembly
{
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = { string('1.2.3.4') }
The issue can be solved by using the .res file. It is not sufficient to do a round trip with ildasm and ilasm. The IL file does not reference the .res file. I had to add it to the ilasm call manually. The data in the res file seemed to contain the infos which are written into the PE header which is ok for me.
The final command line needed was
ilasm test.il /dll /res:test.res
I still do not know what exactly is inside the res file but I can exhange it with the meta data information of any other assemlby that I create manually and then decompile it to replace the metadata of the original assembly as I need.
It seems not many people are doing such stuff.

Grails - Jasper Plugin - Invalid byte 1 of 1-byte UTF-8 sequence error with .jasper file

I am using Grails 1.3.5, SQL Server 2005, iReports 3.7.6, Jasper Plugin 1.1.3. In my GSP page I have given the jasperReprt tag as:
<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />
</g:jasperReport>
For development, in Config.groovy I have specified the
jasper.dir.reports = './reports'
There are two files created in the reports folder when a new report is created and saved, i.e. report.jrxml and report.jasper.
When clicked on the PDF icon in IE or Firefox, an 500 server error is thrown and below is stack trace.
[2010-11-27 01:13:14.998] ERROR groovy.grails.web.errors.GrailsExceptionResolver Invalid byte 1 of 1-byte UTF-8 sequence.
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at
But if I delete the report1.jasper, the error is no longer thrown when PDF icon is clicked and the PDF report is shown fine.
Is this the correct way to do it?
My second issue is with using Sub Reports. Sub report is in the same folder as the main report. But When the report is executed from the application, below error is thrown:
[2010-11-27 01:30:27.556] ERROR groovy.grails.web.errors.GrailsExceptionResolver Could not load object from location : ./reports\report1sub_report.jasper
net.sf.jasperreports.engine.JRException: Could not load object from location : ./reports\urine_routinepatient_details_sub_report.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)
It does not find the sub report. How can I fix it?
Thank you.
Jay Chandran.
Edit:
I have been searching during this whole time, but still could not find a proper solution. So I did some trial and error. I figured out that, deleting report1.jasper and just leaving jasper.jrxml in the report directory works just fine as I said earlier.
For the sub-report issue: It was giving error Could not load object from location : ./reports\report1sub_report.jasper For some strange reason, the main report name report was getting appended to the name sub_report.jasper and was looking for a file named report1sub_report.jasper
So I created a sub-folder under reports folder and named it report1 and updated report1.jrxml file
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>
I had to add the extra \\ slash even though the "SUBREPORT_DIR" parameter had \\ the slashes at the end of the path as shown below.
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>
Notice the \\ at the end. I don't know why it was not getting appended!
Another way would have been to just change the sub-report name from sub_report.jasper
to report1sub_report.jasper!!! :)
I have tested this in production mode and it works fine. I am not sure if this is the way to do it, but all other possible solutions did not work for me.
Feedback will be very helpful.
I assume you have a version conflict here. iReport stores JRXML files and seems to compile them automatically to .jasper. The Grails Jasper plugin picks up the compile variant and gets into trouble with it. So try to disable compiled output in ireport.
The Grails Jasper plugin 1.1.3 uses internally Jasper 3.7.4, the used ireport is 3.7.6.
Regarding the sub reports: no idea.
The MalformedByteSequenceException is caused by a character encoding conflict. I'd suggest to use UTF-8 instead of Windows' Win-1252 (similar to ISO-8859-1) everywhere.
In Jasper's etc/ireport.conf file, change the default_options to:
default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"
(Where Xms and Xmx are unrelated memory settings. If there are default settings with that config entry, you can overtake them, else, just leave them out.)
See this forum thread for alternative configurations.
As for the error with subreports, take a look at the backslash \ that's probably wrong.
EDIT : There is some information about two issues which maybe could help in
http://grails.org/plugin/jasper#faqTab
i hope i can help with one of the issues: which one related with subreports dir.
The problem is the plugin code sets SUBREPORT_DIR to the complete file path of main report, including its name. However the code honour the user provided param with the same name, so if you fill this param with whatever value except null the plugin will use it.
For example if you chain directly the jasper controller you can do:
def renderAs(data,format) {
def reportParams=params.clone()
reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}
In your scenario an (ugly) option would be create an hidden input with name SUBREPORT_DIR and value the desired one. I would fill the paremeter in other way.
EDIT:
Another annoying problem is where do we have to put the main reports and compiled subreports:
When you run the app with run-app they work if you put them all in a folder with the same name as CH.config.jasper.dir.reports(reportDir) in the root of the grails app.
But if you want to deploy a war you have to put the main reports in a folder reportDir in the root of war file and compiled subreports in WEB-INF/classes/reportDir.
I've opted to keep all files in grailsApp/reports and copy the resources in the appropiate folders in the war grails task. In my BuildConfig.groovy i've added (reportDir is "reports"):
grails.war.resources = { stagingDir,args ->
def classpathDir="${stagingDir}/WEB-INF/classes"
copy(toDir:"${stagingDir}/reports") {
fileset(dir:"reports",includes:"**")
}
copy(toDir:"${classpathDir}/reports") {
fileset(dir:"reports",excludes:"**.jrxml")
}
}
Hope it helps.

Resources