I'm trying to learn YAML with C++, i made the given yaml-cpp files into a .dll and .lib file with VC++ Express 2010 by using CMake. I have set up my project the same way i set up other libraries like SFML.
My issue is, when i try to build a Release version of the example code given on the yaml-cpp site i get:
Ogre
Dragon
Wizzard
However, when i try to build a Debug version, i get:
Assertion failed: false, file d:\microsoft visual studio 10.0\vc\include\yaml-cp
p\nodeimpl.h, line 39
I don't know how to handle this. Do i need to build a debug version of the library? If yes, how? I don't know which project options could affect this if i managed to change something.
When i'm compiling, i get a warning:
d:\microsoft visual studio 10.0\vc\include\yaml-cpp\conversion.h(51): warning C4146: unary minus operator applied to unsigned type, result still unsigned
With alot of template printouts, f.e. :
1> d:\microsoft visual studio 10.0\vc\include\yaml-cpp\nodereadimpl.h(35) : see reference to function template instantiation 'bool YAML::ConvertScalar<T>(const YAML::Node &,T &)' being compiled
1> with
1> [
1> T=unsigned int
1> ]
Is this a problem on my side? Bad CMake file and compilation?
> yaml_test.exe!main() Line 108 C++
yaml_test.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
yaml_test.exe!mainCRTStartup() Line 371 C
kernel32.dll!7c817077()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
Aborts at:
doc[i] >> monster;
The program doesn't try to enter the overloaded function.
In my own code it breaks when i try to use my first >> operator, which is the build in one for int.
I'm using the code from http://pastebin.com/PdKWDgQa, though for the original yaml-cpp example code it does the same. The output in Release mode is right, Debug stops and returns the same assert code.
For reference, the stack call in Release mode at the { bracket in the >> function for monster looks like this:
> yaml_test.exe!operator>>(const YAML::Node & node={...}, Monster & monster={...}) Line 36 C++
yaml_test.exe!main() Line 109 C++
msvcr100.dll!_initterm(void (void)* * pfbegin=0x00000001, void (void)* * pfend=0x003a5050) Line 873 C
yaml_test.exe!__tmainCRTStartup() Line 555 + 0x17 bytes C
kernel32.dll!7c817077()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
EDIT:
Actually, i have rebuilt the yaml-cpp project i made with CMake as Debug, everything runs fine when i use it now. I'm sorry if this is obvious, i'm new to these kind of issues.
Related
I have been using wxWidgets to make visual examples of a few of Armadillo's functions. Both matrix transpose and FFT worked perfectly, but when I tried to do a simple polyfit call, the linker fails with a series of errors like these:
> error LNK2019: unresolved external symbol sdot_ referenced in function "double __cdecl arma::blas::dot<double>(unsigned __int64,double const *,double const *)" (?? $dot#N#blas#arma##YAN_KPEBN1#Z)
However, the exact same calls link and run perfectly if I am not also using wxWidgets to display the result. I am using Windows 10 and Visual Studio 2022.
Here is the code that causes the link error. It compiles and links find if the polyfit line is commented out.
vector <double> xcoords = { 7,8,9,10,11,12,13,14,15,16,17 };
vector <double> ycoords = { 32,35,29,34,30,24,32,24,23,28,21 };
arma::vec x = arma::vec(xcoords);
arma::vec y = arma::vec(ycoords);
arma::vec p = arma::polyfit(x, y, 2);
When I installed Armadillo, I ran Cmake . to build the library, but since libopenblas.dll and .lib were already provided, it didn't create an armadillo.lib file. I also tried downloading the latest win64 OpenBLAS libraries, but the same link errors occurred.
I tried replacing the libopenblas.lib and dll from 2016 with those downloaded today. No change. It does not link if the polyfit function is called, but compiles fine if it is commented out.
You would think that a program that calls Armadillo functions would compile and run if you just tell the compiler where the includes are and the linker where the libraries are. This usually works, but for polyfit it does not.
The solution is to copy the example Visual Studio solution file example1_win64.sln and rename it. Then, open that solution and replace the example code with your own, and the program will compile and link.
It is probably a good idea to move that solution file into a directory you create where Visual Studio keeps all its projects, C:\Users\your_name\source\repos
I have managed to build the Kicad 4.0.6 in Linux Mageia 5.1 with gcc version 4.9.2. I first manually fixed two wxWidgets 3.0.2 header files in the /usr/include/wx-3.0/wx/ directory: regex.h and features.h. Kicad then compiled successfully. With the native wx-3.0 headers, the compiler generated the error in pcbnew/netlist_reader.cpp due to the undefined variable wxRE_ADVANCED.
The features.h header checks if the macro WX_NO_REGEX_ADVANCED is defined. If yes, features.h UNdefines wxHAS_REGEX_ADVANCED macro, and defines it, if no. The macro wxHAS_REGEX_ADVANCED, in turn, is used in regex.h to determine if among the enum constants wxRE_ADVANCED = 1 is present. The standard prebuilt Mageia 5 packages wxgtku3.0_0 and lib64wxgtku3.0-devel that I installed with the use of Mageia's software manager urpmi from Mageia repository WX_NO_REGEX_ADVANCED is defined, therefore wxHAS_REGEX_ADVANCED is undefined, and, hence, wxRE_ADVANCED is undefined either. Kicad 4.0.6 source package assumes wxRE_ADVANCED = 1, therefore the build process stops with the error.
Then I reverted /usr/include/wx-3.0/wx/regex.h and features.h to their original state and learned how to add the definition of wxRE_ADVANCED to CMakeLists.txt. However, I still have a question.
The recommended format of adding the definition to CMakeLists.txt I found at CMake command line for C++ #define is this:
if (NOT DEFINED wxRE_ADVANCED)
set(wxRE_ADVANCED 1)
endif()
add_definitions(-DwxRE_ADVANCED=$(wxRE_ADVANCED))
However, it did not work! The macro expansion for wxRE_ADVANCED in pcbnew/netlist_reader.cpp was empty. I printed it at compile time inserting the following lines into the netlist_reader.cpp file (this was hard to find, most of the recommended formats did not work. The correct one is in C preprocessor: expand macro in a #warning):
#define __STRINGIFY(TEXT) #TEXT
#define __WARNING(TEXT) __STRINGIFY(GCC warning TEXT)
#define WARNING(VALUE) __WARNING(__STRINGIFY(wxRE_ADVANCED = VALUE))
Pragma (WARNING(wxRE_ADVANCED))
Finally, I simplified the CMakeLists.txt definition down to this, and it was a success:
if (NOT DEFINED wxRE_ADVANCED)
set(wxRE_ADVANCED 1)
endif()
add_definitions(-DwxRE_ADVANCED=1)
My question: what is the meaning of "-DwxRE_ADVANCED=$(wxRE_ADVANCED)" if it does not work? Is it possible not to use set(wxRE_ADVANCED 1), and simply write add_definitions(-DwxRE_ADVANCED=1)? Thank you.
P.S. Yes, the Kicad 4.0.6 build process successfully finished with only one line added to the top level CMakeLists.txt file:
add_definitions(-DwxRE_ADVANCED=1)
A variable is called via $variable or ${variable}. Note the curly brackets, not parentheses.
Also, it is recommended to use:
target_compile_definitions(mytarget PUBLIC wxRE_ADVANCED=1)
on a target directly, rather than the general add_definitions() command.
I added the Scintilla framework successfully to my XCode project (i.e. it finds the header files correctly), but because it is written in Objective-C++ it doesn't compile. I get 8 syntax errors because of ::s. I already found you can't include Objective-C++ from a pure Objective-C file, so I changed the file extension to mm. It still gives me the same 8 errors.
I also changed the file type (of the importing file) to sourcecode.cpp.objcpp.
The relevant lines of code (with the errors in comments - the line numbers are from the original file, so without the errors in the comments):
ScintillaView.h
// Line 47-49
#protocol ScintillaNotificationProtocol
- (void)notification: (Scintilla::SCNotification*)notification; // 4 errors on this line:
// 1. expected type-specifier
// 2. expected ')'
// 3. expected identifier
// 4. expected ';'
#end
// [snip]
// Line 131
- (void) notification: (Scintilla::SCNotification*) notification; // The exact same errors.
When copying this code I noticed the :: operator is used a few more times in the file, so somehow the parser is only able to match it succesfully in certain places.
Once more, this code is not mine, but taken from the Scintilla Cocoa Library.
(See here for more info: http://www.scintilla.org/)
XCode 3.2.6, Mac OS X 10.6.8
Adding
typedef tdSCNotification Scintilla::SCNotification
Before the first offending line revealed that there was no type called SCNotification in that namespace. So I searched through the included header files (which, luckily, count only three) for namespace Scintilla {. It was in the first included header file, Scintilla.h. But it looked like this:
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
and
#ifdef SCI_NAMESPACE
}
#endif
So I assumed SCI_NAMESPACE wasn't defined. I added #define SCI_NAMESPACE to Scintilla.h somewhere online 45 and it worked. Almost. I got another error message:
Framework not found Scintilla
Command /Developer/usr/bin/llvm-g++-4.2 failed with exit code 1
I think this has to do with how I added the framework to my project, so it should be a separate question.
I'm trying to compile some code for basic USB HID functionality. I'm using a PIC18F14K50 with MPLAB 8.43 and the Microchip C18 compiler.
I'm using some standard files from Microchip's website. Here is my C file and here is my header file.
I'm getting the following error when I build:
Executing: "C:\Program Files\Microchip\mplabc18\v3.40\bin\mplink.exe" /p18F14K50 /l"C:\MCC18\lib" /k"C:\MCC18\bin\LKR" "usb_function_hid.o" "usb_device.o" "enumeration.o" "usb_descriptors.o" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"C:\LPCUSBDK_Labs\Lab1_files\output\Project Lab 1.cof" /M"C:\LPCUSBDK_Labs\Lab1_files\output\Project Lab 1.map" /W
MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Error - could not find definition of symbol 'HIDDescriptor1' in file './usb_function_hid.o'.
Errors : 1
Link step failed.
The HIDDescriptor1 symbol appears in 2 places in the code: PasteBin line 173 of the C file and PasteBin line 356 of the header file.
This code comes straight from Microchip. I'm not sure why it wouldn't be linking. I think either it's designed for another version of the compiler, I'm missing some external dependency, or I'm missing some compiler/linker switches.
Any ideas on what I need to do to get this to build?
In the header file, you have HIDDescriptor1 defined externally. So when you compile usb_function_hid.c, it will compile fine until you try to link it. Then, it cant find that symbol.
It seems that you have to define HIDDescriptor1 in your own code. Or else it is somewhere else in the source that you downloaded, and you need to link that in as well. But it surely isn't defined in the .c file.
EDIT:
I downloaded and installed the Microchip Application Libraries. There is no longer any mention of HIDDescriptor1 in any of the source. However, usb_function_hid.h details another structure that I assume is a replacement:
//USB HID Descriptor header as detailed in section
//"6.2.1 HID Descriptor" of the HID class definition specification
typedef struct _USB_HID_DSC
{
BYTE bLength; //offset 0
BYTE bDescriptorType; //offset 1
WORD bcdHID; //offset 2
BYTE bCountryCode; //offset 4
BYTE bNumDsc; //offset 5
//USB_HID_DSC_HEADER hid_dsc_header[HID_NUM_OF_DSC];
/* HID_NUM_OF_DSC is defined in usbcfg.h */
} USB_HID_DSC;
Browsing the example projects, there are many many HID projects, all which build just fine with the C18 compiler. I recommend downloading this library again; you may have an incomplete or older library. The highlighted project below is for the PIC18F14K50.
I am using CodeBlocks 10.05 with Cygwin 1.7 to compile some C++ codes. The operating system is WinXP SP3. The compiler used is g++ 4.5.3.
When I build the following program:
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned long long a = 12345678901234;
printf("%u\n",a);
return 0;
}
it outputs the following in the build log:
C:\Documents and Settings\Zhi Ping\Desktop\UVa\143\main.cpp||In function ‘int main()’:|
C:\Documents and Settings\Zhi Ping\Desktop\UVa\143\main.cpp|9|warning: format ‘%u’ expects type ‘unsigned int’, but argument 2 has type ‘long long unsigned int’|
C:\Documents and Settings\Zhi Ping\Desktop\UVa\143\main.cpp|9|warning: format ‘%u’ expects type ‘unsigned int’, but argument 2 has type ‘long long unsigned int’|
||=== Build finished: 0 errors, 2 warnings ===|
I do not know why CodeBlocks prints the ‘ etc. symbols. Is there a way for CodeBlocks to properly display the characters?
Cygwin defaults to the UTF-8 encoding, whereas it looks like CodeBlocks assumes that output is in CP1252. Furthermore, since Cygwin tells it that UTF-8 is available, gcc uses separate left and right versions of quote characters instead of the usual ASCII ones. The result is what you're seeing. There are two ways to tackle this: either tell CodeBlocks to use UTF-8, or tell gcc to stick to ASCII by setting LANG=C. I don't know how to do either of these in CodeBlocks though.
Add the following Environment Variable to your computer:
LANG=C
In Windows 7, you can add it by going to Computer > Properties > Advanced System Settings > Environment Variables, then "New...". The menus should be similar in Windows XP.
I hope it's ok to answer an old question. This happened to me today as well, and it took me a while to fix it.