Solved

Building dll in Microsoft C++

Posted on 1999-01-28
8
230 Views
Last Modified: 2010-04-16
HI,

I have been trying to build DLL in MS C++ using extern "C".
Here is my simple code:

#include <stdio.h>^M
#include <math.h>^M
^M
/* extern "C" */^M
extern "C" _declspec(dllexport) void calc1(float,float);^M
^M
void calc1(float x,float y)^M
/* test subroutine for building library */^M
{^M
float z;^M
^M
z= x + y;^M
printf("x=%.2f y=%.2f z=%.2f\n",x,y,z);^M
^M
/* end calc1 */^M
}^M

I just want to compile this in command line mode.
To compile from command line, we used^M
^M
cl -c calc1.c^M
^M
We get the following error message:^M
^M
calc1.c(5) : error C2059: syntax error : 'string'^M

Why is this happening? What am I doing wrong?

Thank you!

JJ


0
Comment
Question by:jinjool
8 Comments
 
LVL 1

Expert Comment

by:peter_vc
Comment Utility
JJ,

I thought you only had to use the extern "C" directive in cpp files.  I believe the compiler is smart enough to know that you are compiling a file with a .C extension, and therefore you should not require the "C".

Peter


0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
peter_vc, I think you found the problem, but you expained it backwards.  The problem is that with a ".c" extension it compiles the program as a C program not a C++ program.  But the solution is to change the file to have a ".cpp" extension.  That way it is compiled as a C++ program.  (I assume that jinjool intended for it to be a C++ program, or he wouldn't have C++ syntax.)
0
 
LVL 4

Expert Comment

by:pellep
Comment Utility
Compiler error C2059 is usually a Syntax Error. line 5 is the printf() command. maybe it's not the extern "C" that's the problem...
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
That line seems fine and is nowhere near 5.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 23

Expert Comment

by:chensu
Comment Utility
Are you using Microsoft C/C++ 7.0 or Microsoft Visual C++? Which version?

Line 5 is extern "C" _declspec(dllexport) void calc1(float,float);
0
 

Author Comment

by:jinjool
Comment Utility
Thank you all for your comments.
Yes, nietod was right. The problem was-- the person who
did the program was running it without a .cpp extension.
I should have known it but somehow completely overlooked
the error.

Thanks again,
JJ
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
So, the points should be given to nietod.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
Comment Utility
Answering as suggested by Chensu (Thanks).  (Sorry, for the delay, I was out of town.)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now