Self-Made Header Files: C

I've been having a bit of trouble making my own header files in C.  I have a basic test program along the lines of:
Main Program:
#include "header.h"
int main(void){
  foo();
Header:
void foo(void);
Header.c
#include "header.h"
defines foo()
So basically, the syntax is correct (as far as I know), but I have trouble compiling it.  I get an undefined function error with gcc.  Are there some command line compilation arguments I'm missing?  Could someone give me a basic walkthrough of how to make/use my own header files?
Thanks.

It's most likely your compilation strategy. When you begin to break things up into mutliple files, you cannot (always) use the gcc form:
gcc main.c -o main
as that actually does 2 things at once.  It compiles main.c and then links it.  That is where the undefined function comes from.  It is a linker error.
To avoid this there are two things you can do.  The "proper" way is to split these steps manually.
gcc -c main.c
gcc -c header.c
The -c flag tells gcc ONLY to compile the code.  This will produce main.o and header.o.
Now, you can link manually, and you need to link ALL objects that contain used functions.  "undefined" errors result from not linking in something that contains a function used.
gcc main.o header.o -o main
Now ./main should run as expected.
Now.  There is a shorthand to this... but I would recommend using the above way, just to make you more familiar with the separation of the two steps AND what kind of errors are compiler errors vs what kind of errors are linker errors.
Shorthand:
gcc main.c header.c -o main
As with the initial usage, this combines both compilation and linking steps.

Similar Messages

  • How to include the RNDISFN.h header file in the WIN CE Build ?

    I need to include the header file RNDISFN.h in the build of the WIN CE OS. By default the file is not included.
    What do i need to include  in the OS design to have the Header file compiled ?
    Who can help ?  (thx in advance to all these brave people that help in this forum)

    Hello Mads, please check my answer to your previous question...
    [click]
    Regards,
    Mariusz

  • How to do a complete cleanup in the repository of a self-made plugin ?

    Hi *,
    How to remove a self made Plug-In from repository ?
    I have got the ARE review and we suppose that this is not supported. Anyway, please try to answer that question and there are two related SR's (7446566.993, 7370886.993) and one Bug is open for that issue.
    Screen prints and the xml file with metric definition are available at GTCR for SR 7446566.993.
    Thanks,
    Torsten

    Hello Torsten,
    "...If we try to re install it after, we still have status down while it is up in reality...."
    As per my understanding of EM, everything is based on TargetGUID, which is a combination of target-name and target-type. Based on this, you may like to give a different target-name and give it a try. (I believe, the reason things work fine is also as explained above. With a different target-type name, the TargetGUID is changed and hence, the behaviour)
    However, both the approaches (a new target-name and/or new target-type name) are not ideal in nature. Check the AVAILABILITY & ALERT tables (don't remember the exact table name(s), though). One of these table holds the status value for targets (and the value is a number - a while back I had investigated on this but am not having the info handy) and the information on alert generated.
    You may also like to clear agent STATEs. Agent maintains state of each metric (& target). Try following:
    1. Stop EM Agent (this is not necessary though)
    2. Execute "emctl clearstate agent" on agent system.
    3. Delete all files under emd/state, emd/recv and emd/upload
    4. Restart the agent (if step 1 was executed)
    5. Check the behaviour of the target status now on target home page
    Hope it helps !
    Regards,
    -Shant

  • Adding self made Xcelsius dashboards to the cockpit in B1 8.8 PL

    Hello,
    How can I add self made Xcelsius dashboards to the cockpit in SAP Business One 8.8 PL12?
    Thanks.

    Hi,
    1) Create your Xcelsius file
    2) Save as SWF (File->Export >SWF)
    3)Open Black Crystal Report and link that SWF file
    4)Save that Crystal report
    5)Import that crystal report by Admin > Setup > general > Report and Layout manager
    6)Save particular location
    now Drag and Drop Crystal report  to your cockpit
    That how i Have link my Xcesius Report
    Thanks
    King Kevin

  • Using Cpp code and header files with LV8 CIN

    Hello,
    I have three pieces of C++ code and their header files that are called from a Main C++ code.  I want to call these from a LV8, code interface node (CIN).  I have the C++ compiler installed on teh same machine as LV8.  My questions are:
    1) How do I call the C++ code anf the header files from the LV CIN?  I have never doen this. Is there a concise manul for this somewhere?  Teh last thing any self-respecting engineer wants to do is read the manual.
    2)  Once I successfully call teh C++ and header files from within the CIN, can I create a LV runtime executable, just as I can with any other LV8 .vi?  Will this runtime .exe run stand-alone as a distribuatble application?  Do I need to include any special runtime files when I build the exectuable to support teh C++ code?
    Thank you.

    http://forums.ni.com/ni/board/message?board.id=231&message.id=2424&requireLogin=False
    handles your question.

  • Header file WITHOUT javah..

    Hi,
    i searched the web but didn't found anything. Is there any kind of 'specification' how to get the declaration of the native method implementation in C just from the declaration of the native method declaration in java?
    thanks :-)

    Hi
    if you dont want to use the JAVAH tool to generate the C header files , you can do it your self.
    The fucntion should have the the follwing signature:
    1) for member function
    JNIEXPORT jobject JNICALL Java_<PACKAGE NAME>_<CLASS NAME>_<METHOD NAME>
    (JNIEnv *env,jobject obj)2) For Static functions
    JNIEXPORT jobject JNICALL Java_<PACKAGE NAME>_<CLASS NAME>_<METHOD NAME>
    (JNIEnv *env,jclass obj)regards
    pradish

  • [SOLVED] Where do header files come from?

    I'm a little confused about which files get included when compiling a program in C.
    I made a file named "screen.h". It's pretty obvious that the compiler is trying to use a different "screen.h" than mine, especially since it compiles fine when I rename my file to "screenblarg.h".
    I am making a video game using the Allegro Game Library. Here is the command I use to compile the source files:
    gcc -O2 -Wall -Wextra -ansi -pedantic -c filename.c -I/usr/include
    I "properly" include the necessary files, using quotes and angled brackets, for example, in "main.c":
    #include <allegro.h> /* System header */
    #include "screen.h" /* Local header */
    I'm especially confused because there is no "screen.h" in "/usr/include".
    Does this behavior make sense to anyone? Please let me know if it would help to see the actual code. Thank you!
    Last edited by drcouzelis (2010-08-11 02:00:11)

    tavianator wrote:
    Use gcc -v to see where it's searching for include files.
    Also, -I/usr/include is unnecessary, as gcc will search there for includes by default.
    Thank you for your response. I don't see anything in the output of "gcc -v" that would say where it is searching for header files. (it's from the standard Arch Linux package, by the way)
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
    Target: x86_64-unknown-linux-gnu
    Configured with: ../configure --prefix=/usr --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object --enable-lto --enable-plugin --disable-multilib --disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
    Thread model: posix
    gcc version 4.5.0 20100610 (prerelease) (GCC)
    As for including "-I/usr/include", I understand that it's not necessary. It comes from the Allegro command "allegro-config --cflags" in my makefile, which I added to make compiling my program a bit more portable.
    There are two other files on my computer named "screen.h". I tried renaming them, but my program would still not compile.
    A search on the Internet doesn't say anything about a common "screen.h" file in Linux.
    Does the compiler "see" header files (such as a "screen.h") in the libraries that are in "/usr/lib"? Or something? O_o

  • Xmlstarlet and header files confusion

    I'm trying to make a package out of xmlstarlet. Just running configure and then make has me running into this error:
    ad /usr/lib/libxml2.a -lz -lm -lpthread -ldl -L/usr/lib
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoGcryptInit':
    crypto.c:(.text+0x15c): undefined reference to `gcry_check_version'
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoRc4DecryptFunction':
    crypto.c:(.text+0x2d4): undefined reference to `gcry_cipher_open'
    crypto.c:(.text+0x2fe): undefined reference to `gcry_cipher_ctl'
    crypto.c:(.text+0x327): undefined reference to `gcry_cipher_decrypt'
    crypto.c:(.text+0x333): undefined reference to `gcry_strerror'
    crypto.c:(.text+0x36f): undefined reference to `gcry_cipher_close'
    crypto.c:(.text+0x47c): undefined reference to `gcry_strerror'
    crypto.c:(.text+0x4bc): undefined reference to `gcry_strerror'
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoRc4EncryptFunction':
    crypto.c:(.text+0x60f): undefined reference to `gcry_cipher_open'
    crypto.c:(.text+0x639): undefined reference to `gcry_cipher_ctl'
    crypto.c:(.text+0x668): undefined reference to `gcry_cipher_encrypt'
    crypto.c:(.text+0x674): undefined reference to `gcry_strerror'
    crypto.c:(.text+0x6b0): undefined reference to `gcry_cipher_close'
    crypto.c:(.text+0x814): undefined reference to `gcry_strerror'
    crypto.c:(.text+0x854): undefined reference to `gcry_strerror'
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoSha1Function':
    crypto.c:(.text+0x90c): undefined reference to `gcry_md_hash_buffer'
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoMd5Function':
    crypto.c:(.text+0xa0c): undefined reference to `gcry_md_hash_buffer'
    /usr/lib/libexslt.a(crypto.o): In function `exsltCryptoMd4Function':
    crypto.c:(.text+0xb0c): undefined reference to `gcry_md_hash_buffer'
    collect2: ld returned 1 exit status
    make[2]: *** [xml] Error 1
    make[2]: Leaving directory `/tmp/xmlstarlet-1.0.1/src'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/tmp/xmlstarlet-1.0.1'
    make: *** [all-recursive-am] Error 2
    Now, I don't know how to interpret that error, but the Soureforge page does contain the following advice which I figured might be pertinent:
    Make sure that libxml2 and libxslt header files matches (by version) with libraries you are linking. The versions of include files can be found in ${include_prefix}/libxml2/libxml/xmlversion.h and ${include_prefix}/libxslt/xsltconfig.h
    Using find I came up with the files
    /usr/include/libxslt/xsltconfig.h
    /usr/include/libxml2/libxml/xmlversion.h
    and digging into them made it clear that libxml was version 2.6.32 and libxslt was 1.1.24. But I don't knwo how to match that? Or if this is even remotely relevant to the error message, I'm seeing?

    chochem wrote:bugger... I just submitted it but I can't find any way to submit my .install file alongside it - any hints?
    Just include it in your package and resubmit it (the new package will replace the old one). Also, MIT is not a standard license so you need to store a copy of it in /usr/share/licenses/<package name>/ (read the wiki for more information on this).

  • Session variable and Tracking in Header file

    Is there a way for me to keep track of the session and use a variable in my Header to pass around for this?
    I have a login.jsp, validate_login.jsp and other jsp's that have the same header file. Instead of me using the same code in all of the jsp's I thought it would be easier to put it in the header Please look at the example code below:
    // validate_login.jsp is passed username and password from the login.jsp.
    // validate_login then calls the logIn method in my Session class.
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="uom.edu.rd.session.Session"%>
    <html>
    <head><title>Validate Login</title></head>
    <body>
    <jsp:include page="header.jsp" />
    <%
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        this_session.logIn(username, password);   
        boolean b = this_session.getLoggedIn();
    %>
    ==================================================================
    // The logIn method in Session class
    public void logIn(String userName, String password) {
             Connection con = null;
             Statement stmt = null;
             ResultSet rs = null;
             try{
                con = db.getConnection();
                 stmt = con.createStatement();
                 String sql = "SELECT * FROM RD_USER WHERE USER_NAME = '" + userName +"' AND USER_PASSWORD = '" + password + "'";
                  rs = stmt.executeQuery(sql);
                  if(rs.next()){
                       loggedIn=true;
                  }else{
                       loggedIn=false;
             catch(Exception e){
                  // If something goes wrong, make sure
                  // the user is not logged in.
                  loggedIn=false;
              }finally{
                  try{
                       rs.close();
                       stmt.close();
                       con.close();
              }catch(Exception e){
         * Log the user out.
        public void logOut() {
             loggedIn = false;
         * Get the login status.
         * @return boolean
        public boolean getLoggedIn() {
             return loggedIn;
    ==================================================================
    // and this is part of my header.jsp
    <%@page import="uom.edu.rd.session.Session"%>
    <%
      Session this_session = Session.findSession(request);
      if ( this_session==null ) {
          /* Now, instead of redirecting, create a new Session
           * object and initialize it.
          this_session = new Session();
          this_session.makeSession(request);
          this_session.createQueryBuilder(config);     
    %>
    // This is the part I would like to pass around
    <!-- Session logged_in = new Session(); -->
    <%   
        boolean loggedIn = this_session.getLoggedIn();    
            if (loggedIn == false)
            { %>
                <A STYLE="color:#FFFFFF;text-decoration:none;" HREF="./login.jsp"><FONT COLOR="#FFFFFF">LOG IN</font></a>  <FONT COLOR="#FFFFFF"></font>
        <%  } else { %>
                <A STYLE="color:#FFFFFF;text-decoration:none;" HREF="./logout.jsp"><FONT COLOR="#FFFFFF">LOG OUT</font></a>  <FONT COLOR="#FFFFFF"></font>
         <% }
    %>
    // so if you are logged in  then you are able to view certain things on the jsp's if you are not logged in
    // then of course you cannot. I want to pass around this loggedIn variable to all the jsp's
    // after it checks  loggIn Status for each page I have tried running this but I keep getting an error: cannot resolve symbol this_session

    Use <%@ include file="header.jsp" %> instead

  • How can I use a dll if I dont have a header file

    I'm not sure if I'm even trying the possible here as I have searched and not been able to find much at all.  However I figured it was worth asking here.
    I have access to several dll's used by a program, I need to open a file using the program (for some reason it is completely non responsive unless you open it "within" the program itself) and so decided to browse the .dll files included.  Ive found a few functions which may carry out the function I need.  Is there a way of figuring out the inputs/outputs if I don't have documentation or a header file?
    This is the next stage in a huge project I am working on at the moment and I've been banging my head against the wall all day trying to figure this out.
    Thanks in advance for any help
    Rik
    That glass?
    Thats glass is neither half full or half empty....
    Its twice the size it needs to be

    Yes, that makes sense. It also means that what you are trying to do is not likely to work. You have no way of knowing what the program does when opening the file, so guessing at using the DLLs is purely a shot in the dark without even knowing where the dark is. Even if you could find the function (assuming it's just one) that loads a file, how is the program supposed to use it now? That function has to be called from within the program. When you call it from LabVIEW you are not sitting inside the program's memory space, so it has no way of knowing about the file.
    I would suggest, instead, to see if the program accepts command-line parameters. For example, does it accept a name of a file to open as part of launching it from the command line? If not, then you may need to resort to trying to control it via automation. If it has no built-in automation then you need to resort to using the OS to make pretend you're clicking buttons and typing text. This has come up many times before, and there have been numerous posts on this, so please do a search on controlling an external program from LabVIEW within this forum. You can call the Windows API functions to move the mouse to a specific location and click the button as well as typing text, or you can use third-part automation tools. One that I have used successfully is AutoIt. The search I indicated will yield other suggestions. 

  • How to use preprocess​or directives (#define) in C++ header file with LabVIEW 8.2

    I have a C++ header file that contains around 2000 preprocessor directives:
    #define MEM_1   0xC
    #define MEM_2   0xD
    #define MEM_3   0x18
    I want to be able to "access" these memory offsets by identifier name (MEM_1) in my LabVIEW program like I would in a C++ program.  I do not want the overhead of parsing through the header file and storing all the offsets into an array or similar structure. 
    I've written a simple Win32 console program to return the memory offset given the identifier (see code below), and created a DLL to use with my LabVIEW program.  In the console program, you notice that I can call a function and pass in the identifer name, and get the offset back correctly:
    getOffset(MEM_1);
    In LabVIEW, I was hoping to be able to pass in the identifier (MEM_1) but was unsure what datatype to use.  In my C++ code, I defined the parameter as an int.  But in LabVIEW, I can't enter in MEM_1 as an int.   Can someone advise on how to do this?  Or if there is an alternate way to use #define's from external code inside LabVIEW?
    #include "stdafx.h"
    #include "scrmem.h"
    #include "stdio.h"
    void getOffset (int var);
    int _tmain(int argc, _TCHAR* argv[])
     getOffset(MEM_1);
    canf("%d");
     return 0;
    void getOffset (int var)
     printf("The address of MEM_1 is %x", var); 

    kaycea114 wrote:
    Hi,
    Where do you think I should use the string? 
    The way that getOffset is currently defined in the DLL, I have to connect an integer input into the LabVIEW function.  This prevents me from entering in: MEM_1 as the input to the LabVIEW function.
    Are you suggesting that I change getOffset to receive a String parameter ("MEM_1")?  Does that mean I need to do a string compare (line by line) through the header file to get the offset?  It seems like doing this search through the header file would degrade performance, but if that's the only work around, then I'll do it.
    Please advise.
    Well, what you want to do is indeed entering a string and getting back the assigned integer. That is what the C preprocessor is doing too although there it is done only once at the preprocessor stage of course and not at runtime anymore. But LabVIEW is not a C preprocessor.
    What you did so far seems to be to define getOffset() that accepts an enum that needs to be created from the C source code to then return the assigned constant. That's of course not very helpful.
    And writing a VI that could parse the C header file and create a name/constant array is really a lot easier than doing the same in C. You don't even need to parse the file each time again, but can instead cache them in an uninitialized shift register (LV2 style global).
    Even more easy would be to create from that data a ring control using property nodes and save it as custom control and voila you have the most direct lookup you can get in LabVIEW and it works just as comfortable as using the define in C code. It would mean that you need to seperate your header file possibly into several different files to only get related constants into the same ring control, but that is easily done.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Header file entry for Text Channel

    I have taken an ASCII Text Data file, read the file, and created a Header File, then saved the data into a binary file. This is my attempt to speed up the loading of the text file. One of the columns is a text column, containing a flag for the state of the test. I can not figure out how to define the column as a Text Column in the Header File. If I define it as a numeric column, it returns an error for every entry in the data file. Normal (one of the states) is not a Numeric Value.
    The script file(s) I am using is a modification of a script listed on this board by Brad Turpin ( TimeSlice DAT Hdr Create.zip ) The only thing I have changed is the Test for the Channel Name to see if it contains on of 3 states. If Date is present in the Channel Name , it changes the field to a Time channel, if the channel contains Relay it changes it to a Text channel (which doesn't work), else the Channel is a Numeric.
    There must be a way to define a Text Channel in a Header File. I hope someone can show me the way.
    Thanks
    Bill Lane
    Test Engineer
    Takata, INC.

    Hello Bill!
    The DAT format was never able to store text channels (TDM is able today). Please refer to the DAT format description on your DIAdem CD or in this post.
    Your idea to convert it to a numeric value is the right way. The error message must come out of the header. Do you convert all properties to numeric values? See page 4-6 and following in the header description or search for the word 'normal' in the created header file.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • Problem while including the header file in C source code in CIN

    While Creating code interface node....
    In the C source code we are supposed to include the Header file "extcode.h".In my system i have installed
    Turbo C. I couldn't able to find the above header files.When i am trying to use the above header file i am getting error,what could be the reason

    Hi,
    You need to point your turbo C to ..\labview\cintools which is where you will find the extcode.h and other h file and also the lib file.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • HT4796 I have made a file using the Pages app.I mailed it to a friend.When she tried opening the same file on her pc at home , It did not open.Please help me as to how to open the file in the Microsoft word format on her pc.

    I have made a file using the Pages app.I mailed it to a friend.When she tried opening the same file on her pc at home , It did not open.Please help me as to how to open the file in the Microsoft word format on her pc.

    Send it as a PDF.

  • How to use an self-made iView in the Portal Content?

    Hi everybody,
    I followed the instructions to set up a Portal (6.0 SP 2) with the PDK. Now I just wrote a simple "Hello-World" iView and deployed it into the portal server. It worked fine when I clicked to test it in the Java Development Inspector.
    But...
    In the Portal Content I can not find my self-made iView? How do I get it there? I coudn't find any documentation.
    I'd appreciate your help!

    In the portal content try to create a new Iview and select the option (create new iview from portal Archive).
    After selecting that you will see all the PARs deployed on your server, just select yours and follow on.
    Hope that helps.
    Thanks
    Ankur

Maybe you are looking for

  • Updating to itunes 10.6 in windows 7

    just trying to update to itunes 10.6 as I have pruchased a new iphone4g and it wouldn't let me use the current version. the 10.6 version download completes, but the install gets stuck on "publishing product information" and then rolls back and uninst

  • ITunes will not recognize my ipod in the computer.

    I don't know why iTunes won't recognize my iPod...

  • X58A-GD65 USB3 problem with WD MyBook

    Hi, I have X58A-GD65 with i7 processor, 6 GB RAM, 4 internal HDD, 4 external HDD, Win 7 x64. Two of the external are WD MyBook Essential USB 3.0/2.0. My Renesas drivers are v 2.0.34.0 (the ones from the board page). When I plug two of the WD drives,

  • Social Media and The Studio

    I'm currently due for an upgrade, and I want to stick with a feature phone.  I'm stuck on weather I should get the LG Cosmos Touch or the KIN TWOm.  I'm leaning towards the KIN TWOm right now, but I need to know a few things.  I recently read an arti

  • Multiple soundcards

    Hi, I bought an usb sound card M-Audio Transit and I have trouble to get it work well. When I load the firmware using madfuload, I can see the card in /proc/asound/cards, but I don't know how to completely switch to it. Sound from some applications g