Visual C++ :: Using Macro To Generate DEF File

Nov 30, 2012

I'm trying to build libglib using MSVC. libglib doesn't use dllexport - so to create usable DLLs it needs to generate a .DEF file. It does this by using a .symbols file. Here's a cut-down example:-

Code:
/* This file lists all exported symbols. It is used to generate the glib.def file used to control exports on Windows.*/

/* glib.symbols */
g_mkdir_with_parents

#ifdef G_OS_WIN32
g_file_get_contents_utf8
#endif

The following commands would produce the following files called glib.def

Code:
cl /EP glib.symbols > glib.def

produces this in glib.def:-
g_mkdir_with_parents

Code:
whereas this:-
cl /EP -DG_OS_WIN32 glib.symbols > glib.def

produces this in glib.def:-
g_mkdir_with_parents
g_file_get_contents_utf8

So this is a handy way of producing conditional .DEF files. Fortunately, this can all be built into a Visual Studio macro in my vsprops file - e.g.

Code:
<UserMacro
Name="GlibGenerateGlibDef"
Value="echo >"$(SolutionDir)glib.def" && cl /EP -DG_OS_WIN32 glib.symbols >>"$(SolutionDir)glib.def""
/>

Problem:- Although I can run the macro as a pre-build step (and it does produce conditional entries in the generated .DEF file) it DOESN'T produce the word EXPORTS at the top of the file. So the linker then fails to recognise it as a valid .DEF file.

How can I add that word EXPORTS to the top of the generated file? I tried just adding EXPORTS to the top of the symbols file but that didn't work. I also tried this variation on the macro:-

Code:
Name="GlibGenerateGlibDef"
Value="echo EXPORTS >"$(SolutionDir)glib.def" && cl /EP -DG_OS_WIN32 glib.symbols

But that didn't work either I feel sure there must be a way to do this.

View 1 Replies


ADVERTISEMENT

Visual C++ :: Macro With Multiple Parameters

Oct 22, 2014

In the following example, SET_DARKENING_PARAMETERS_0 is a fairly simple macro which accepts 9 parameters. The first one is called driver and the other 8 are all ints. Basically, the 8 x ints get assigned to the first 8 elements of an array which is owned by driver. I can call the macro successfully if I do this:-

Code: SET_DARKENING_PARAMETERS_0 ( some_driver, 500, 400, 1000, 275, 1667, 275, 2333, 0 );

But in the actual code I'm trying to compile, the 8 x ints are themselves encoded into a secondary macro like this:-

Code: #define CONFIG_OPTION_DARKENING_PARAMETERS 500, 400, 1000, 275, 1667, 275, 2333, 0

So the actual code (to call SET_DARKENING_PARAMETERS_0) looks like this:-

Code: SET_DARKENING_PARAMETERS_0 ( some_driver, CONFIG_OPTION_DARKENING_PARAMETERS );

But the two combined macros won't compile with VC8. Basically, I get warning #C4003 (not enough parameters for macro 'SET_DARKENING_PARAMETERS_0') followed by a load of syntax errors. However, the code (allegedly) compiles with gcc.

I'm wondering if macro CONFIG_OPTION_DARKENING_PARAMETERS might be getting truncated to just 500, (with the following parameters getting ignored)?

View 5 Replies View Related

C++ :: Define A Macro Within A Macro?

Feb 26, 2012

Is it possible to define a macro with in a macro? Any trick will do. I am trying to do quick conversion of cuda program to open mp by defining some macros at the top:

Code:
#define __syncthreads() #pragma omp barrier

View 2 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml . They are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related

C++ :: Read Input File (XML) And Generate Output File

Mar 25, 2013

I have code that reads an input file and generates an output file .For reading the input file we have a xml file.If there is an error while reading or writing the output file the an errored file is generated. But in the errrored file the fields are not coming as in accordance with the reader xml .they are coming randomly . In the module for reading and writing the errored file list is being used . What should be done to write in the errored file as the reader xml fields.

View 1 Replies View Related

Visual C++ :: Generate Class Average For Entered Test Scores

Jan 14, 2013

Below is the program I have written yet I can't seem to get it to work right.

// Purpose: generate a class average for entered test scores
// Input: # of tests, test scores
// Output: total number of tests, average score of tests

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//declare variables
short numberOfTests = 0;

[Code] .....

View 6 Replies View Related

C :: How To Generate DLL File In Eclipse

Nov 16, 2013

I just re-installed my OS some days ago,which contained Visual Studio.But I don't want to use the VS any more(at least in my computer) as the interminable installing process.Then I take Eclipse as my C/C++ IDE by MinGW and CDT. My Java program need to load an DLL file which wrote by C.But when I generating the DLL file,I got some errors.It seems that the compiler cannot find the header files. By the way,I just want to implement the hello-world program in C and invoke it in the Java program.This is my Java testing program:

Code:

public class HelloWorld{ public native void printHelloWorld();
static{
System.loadLibrary("hello");
}
public static void main(String[] args){
new HelloWorld().printHelloWorld();
}
}

And this is the header file generating by "javah HelloWorld":

Code:

/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif

[code]....

View 1 Replies View Related

C++ :: Generate Random Numbers To A File?

Apr 3, 2013

The program is to generate random numbers to a file and will have one integer parameter, Open a file and then using a loop write the required number of random numbers to the file. Scale the random numbers from 1 and 100 inclusive. Then closes the file .The last function will read the numbers in the file into your program. so far i have

Code: #include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <cstdlib>

[Code] .....

View 12 Replies View Related

C :: How To Generate List Of Struct Members Using Header File As Input

Jun 25, 2014

I need to create a list of all members of a struct using the sturct definition as input. The struct is NOT part of the program, but is the input to the program.

The struct that I am using changes over time as features are added. I need the complete, fully qualified field names to then generate a table with all names with their offsets, type and length.

This information then allows me to create readers of the data that will run on different architectures, compilers and operating systems.

The struct currently has 800+ lines and uses typedef and embedded structs.

Perhaps this could be done creating LEX, YACC, Perl, SED, AWK or other language system.

View 6 Replies View Related

C++ :: Generate A Report Based On Input Received From A Text File

Nov 5, 2014

Here is the assignment... Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy. And the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

and this is the code I have so far...

#include <cstdlib>
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
enum class_level {FRESHMAN, SOPHOMORE,JUNIOR,SENIOR};
class_level classLevel;

[Code] .....

My main question is did I use the namespaces and enum correctly? And my second question is whats the best way to input the data from the text file? This is really where I get stuck.

View 3 Replies View Related

C++ :: Generate A Report Based On Input Received From Text File

Nov 7, 2014

Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
The second namespace globalType fys should derive the class level based on a four year school policy.

So I basically did it in parts and got everything working and then had to make the namespace so I had this:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };

[Code] ......

I know I have to clean it up and change it but it ran like it was suppose to. Then I tried adding the global namespaces and I this:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;

[Code] ....

with this i keep getting an error saying tys::deriveClassLevel: must return a value and tys::fys::deriveClassLevel: must return a value. I have been messing around with this part and struggling I thought I used the namespace to run the if statements with the criteria for the years of school. Basically I have been stuck for awhile and trying to change things around but I cant seem to get it to work.

View 2 Replies View Related

C :: Original Text File / Generate Another File With Text Content In Upper Case

Nov 29, 2014

Code software that, from an original text file, generate another file with the text content in upper case.For exemple:

entrence:

luke
tom
alex

outings:

LUKE
TOM
ALEX

My code so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}

[code]....

View 2 Replies View Related

C++ :: Generate Report Based On Input Received From Text File - User Defined Namespace

Nov 11, 2014

Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character.

For example :
ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);

while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
transferSchoolFile.ignore(); //Used here to ignore the newline character.
….
}

I did this in parts so I got it working with a four year criteria without the user defined name spaces.

include <iostream>
#include <fstream>
#include <string>

using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };

[Code] ....

So that worked fine then I tried with name spaces -

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;

[Code] ....

I know I have some stuff to mess around with but I am currently stuck with two errors, first -

Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1

then -

Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1

View 1 Replies View Related

C/C++ :: Generate Report Based On Input Received From Text File - User Defined Namespace

Nov 11, 2014

Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student's name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character. For example :

ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);
while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;

[Code] ....

I know I have some stuff to mess around with but I am currently stuck with two errors, first -

Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1

then -

Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1

View 2 Replies View Related

C :: Defining And Using A Macro

Jan 4, 2015

I am trying to create a small set of filepath functions that I intend to compile across linux and windows (I prefer not to use a big library). I want to have a global constant PATH_SEPARATOR that depends on the OS environment. This is what I set at the top of header file.

Code:

#include <stdio.h>
const char PATH_SEPARATOR =
#ifdef _WIN32
'';
#else
'/';
#endif I was hoping to test this while compiling this in a linux environment using gcc, thusly:

Code:

int main (int argc, char const* argv[])
}

[code]....

where apparently, I seem not to be able to "set" a part of the code to have "_WIN32" defined. I don't know if I explained this clearly.

View 5 Replies View Related

C++ :: Macro To Template?

Mar 22, 2013

I have this macro, that expands to some methods of my class:

Code:
#define POPULAR_COMBO_FILTRO_COM_BASE(classeTabela)
void VisualizadorLogsFrame::PopularComboFiltroCom ## classeTabela (bool limparTexto) {
long from, to;
m_cbxDetalhe->GetSelection(&from, &to);

[Code]...

but I get a compile error on this line:

Code:
for (list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); linha++) {

what am I doing wrong ? the error is:

VisualizadorLogsMain.h:174: error: expected ';' before 'linha'
VisualizadorLogsMain.h:174: error: 'linha' was not declared in this scope

View 4 Replies View Related

C :: Variadic Macro Function

Sep 12, 2013

I'm doing right now is creating a function that callocs (I prefer this to malloc) and returns a string, and it will work similar to printf, I'm calling the function alloCpy(),I have several values that I need in a malloced string, so I call Code: myAllocedString = alloCpy("Value 1 is %s, value 2 is %s, and value 3 is %d", str1, str2, num); To do this I'm using the Variadic Macro, the reason I'm not just using a Variadic Function such as this: Code: char* alloCpy(char *format, ...) {} is because I need to append NULL to the end for the sake of looping through arguments, and I'm understanding it thusfar, but I have a few issues, first of all, I tried defining the Macro in a header file, but when I try to call it I get the error "Undefined reference to alloCpy". Also, to loop through arguments to get string lengths I'm using va_arg(args, char*) which requires all the arguments to be of type char*. Here is my code:
myheader.h:

Code:

#define alloCpy(format, ...) _alloCpy(format, ##__VA_ARGS__, NULL);
char* _alloCpy(char *format, ...); mycfile.c: Code: char* _alloCpy(char *format, ...) {
va_list args;
va_start(args, format);
int args_len = 0;
}

[code]....

So, how can I do this to, first of all, make my macro function accessible from other files importing myheader.h, and second, how can I make it accept any type of argument like printf, so that my example above would work?

View 3 Replies View Related

C :: Testing If A Macro Is Defined To A Value?

Jan 16, 2015

Say I have something lke

Code:
#define FOO BAR
#if FOO == BAR
doX();
#else
doY();
#endif

This causes doX(); to be executed. But the intent is to have doY(); be run. I'm guessing this is because BAR is undefined and therefore blank, so blank equals blank. Is there some way to compare the symbol FOO was set to instead of its value, BAR?

View 4 Replies View Related

C++ :: Replacing Macro With Constant

Apr 4, 2013

I heard that const shall be preferred over #define . So I start to change my program accordingly.

But then below error message occurs during compilation:

#include "common.h"
#include "definition.h"
#include "particle.h"
int main() {
Particle *p = new Particle();

[Code] .....

I guess the error occurs because, when the line 9 of particle.h (File 4) is compiled, value of const int dimension is not seen by the compiler.

View 6 Replies View Related

C/C++ :: Migration Of Serialization Macro

Jun 12, 2014

I have to migrate C++ source which is compiled with MinGW-gcc to be compiled with VS2013, and have one issue with one macro used for serialization.

Here is macro:

#define IMPLEMENT_SERIALIZE(statements)
unsigned int GetSerializeSize(int nType, int nVersion) const
{
CSerActionGetSerializeSize ser_action;
const bool fGetSize = true;

[Code] ....

Here is place in code were it is call (in class declaration):

IMPLEMENT_SERIALIZE(({
if (!fRead) {
uint64 nVal = CompressAmount(txout.nValue);
READWRITE(VARINT(nVal));

[Code] .....

When compile received errors:

main.h(555): error C2059: syntax error : '{'
main.h(555): error C2143: syntax error : missing ';' before '{'
line 555 is end of macro call ( "})").

How should look using of this macro in order to avoid that errors?

View 7 Replies View Related

C++ :: Pitfalls Of Macro Substitution?

Dec 29, 2013

"If you examine the expansion of max, you will notice some pitfalls. The expressions are evaluated twice; this is bad if they involve side effects like increment operators or input and output. For instance, the below example will increment the larger twice."

#define max(A, B) ((A) > (B) ? (A) : (B))

max(i++, j++)/* WRONG */

I don't see what the problem is with the code above. i is incremented and j is incremented and then it performs a ternary operation to see which is greater. Am I missing something?

View 1 Replies View Related

C++ :: Two Projects - Defining Value Of Macro

Jun 27, 2012

Say I have two projects A and B. A depends on B. If project A defines a macro to be 100 and project B defines the same macro to be 200. In project A, if I use this macro, what value would this macro be? Let's just forget macro is evil for the time being. Let's also forget that it is not good to define the same macro twice for the time being.

View 8 Replies View Related

C :: How Macro Works To Concatenate Three Integers

Nov 15, 2014

when i was finding a way to concatenate three integers in C, I came across a snippet like this

Code:

#include<stdio.h>
#define cat(a,b,c) a##b##c
int main()
{
int d;
d=cat(1,2,3);
return 0;
}

How the macro works here? I am unable to understand the function '#' plays in the macro.

View 1 Replies View Related

C :: Writing A Macro That Returns A Boolean Value

Apr 24, 2014

I need writing a macro that would return true/false (1/0) )value. I want to check if a certain element exists in the array. The macro will accept array, its size, and the value to be compared, and must return yes or no. Here is the code that I have written:

Code:
#define EXISTS(T, a, n, val) do {
char ret=0;
T *a_ = (a);
size_t n_ = (n);
for (; n_ > 0; --n_, ++a_){
ret = (*a_ == val);
}
}
while(0)

How can I get the result from this macro.

View 6 Replies View Related

C++ :: Macro For Changing Array Size

Nov 22, 2013

I'm trying building a new macro for change the array size:

#define redim(varname,x) ((sizeof(varname)*) realloc (varname, x * sizeof(varname)));
int b;
redim(b,3);

error message:
"error: expected primary-expression before ')' token"

what isn't right with these macro?

View 10 Replies View Related

C++ :: Linking To Static Library That Contains A Macro

Jul 16, 2014

I have built a static library that contains a macro. From a separate exe, I am calling this macro, but it doesn't work.

The compilation of the static library and that of the exe went okay.

Static lib contains just the macro definition.

Exe contains call to this macro.

Is there anything else that I need to do for this to work?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved