Почему я получаю следующую ошибку компоновки: неопределенная ссылка на `__printf__'

Я использую Clion от JaetBrains с MinGW 3.2.1 для Windows. и я пытаюсь построить проект в c. Я продолжаю получать следующую ошибку связывания: неопределенная ссылка на `printf'

любая идея Как это решить?

это мой код:

#include <fcntl.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h> // for time measurement
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <libintl.h>

#define BUFFERSIZE 1

int main(int argc, char** argv) {
   assert(argc == 3);

char* inputDirPath = argv[0];
char* keyFilePath = argv[1];
char* outputDirPath = argv[2];

// open key file
int key_fd = open(keyFilePath, O_RDONLY);

if (key_fd < 0) {
    printf("Failed opening Key file %s. Error: %s\n", keyFilePath, strerror(errno));
    return errno;
}

// making sure the file is not empty
char keyFirstChar;
if (read(key_fd, (void*)keyFirstChar, 1) == 0)
{
    printf("Error. Key file is empty %s.", keyFilePath);
    return errno;
}
else {
    // go back to the begining of the file.
    assert(!close(key_fd));
    key_fd = open(keyFilePath, O_RDONLY);

    if (key_fd < 0) {
        printf("Failed opening Key file %s. Error: %s\n", keyFilePath,

               strerror(errno)

        );
        return errno;
    }
}


// Temp file name
char inputFilepath[200] ;

struct dirent *dirEntity;
DIR *inputDir_dfd;

// open directory stream
assert((inputDir_dfd = opendir(inputDirPath)) != NULL);


while ((dirEntity = readdir(inputDir_dfd)) != NULL)
{
    // full path to input file
    sprintf(inputFilepath, "%s/%s",inputDirPath, dirEntity->d_name) ;

    // call stat to get file metadata
    struct stat statbuf ;
    assert( stat(inputFilepath,&statbuf ) != -1 );

    // skip directories
    if ( ( statbuf.st_mode & S_IFMT ) == S_IFDIR )
    {
        continue;
    }

    // open input file
    int inputFile_fd = open(inputFilepath, O_RDONLY);

    if (inputFile_fd < 0) {
        printf("Failed opening file in input directory, %s. Error: %s\n", inputFilepath, strerror(errno));
        return errno;
    }

    // Temp file name
    char outputFilePath[200] ;

    // full path to file
    sprintf(outputFilePath, "%s/%s",outputDirPath, dirEntity->d_name) ;

    // open input file
    int outputFile_fd = open(outputFilePath, O_WRONLY | O_CREAT | O_TRUNC);

    if (outputFile_fd < 0) {
        printf("Failed opening file in output directory, %s. Error: %s\n", outputFilePath, strerror(errno));
        return errno;
    }

    char inputFileBuf[BUFFERSIZE];
    while (read(inputFile_fd, inputFileBuf, BUFFERSIZE) == BUFFERSIZE){

            char keyFileBuf[BUFFERSIZE];

           if (read(key_fd, keyFileBuf, BUFFERSIZE) == 0) {
               assert(!close(key_fd));
               key_fd = open(keyFilePath, O_RDONLY);

               if (key_fd < 0) {
                   printf("Failed opening Key file %s. Error: %s\n", keyFilePath, strerror(errno));
                   return errno;
               }
               read(key_fd,keyFileBuf, BUFFERSIZE);
           }

           char outputToWrite[BUFFERSIZE];
           int i;
           for(i = 0; i < BUFFERSIZE; i++){
               outputToWrite[i] = keyFileBuf[i] ^ inputFileBuf[1];
           }

           if( write(outputFile_fd, outputToWrite, BUFFERSIZE) == -1){
               printf("Failed writing to output file, %s. Error: %s\n", outputFilePath, strerror(errno));
               return errno;
           };
       }


       if(close(inputFile_fd) ); // close key file
   }
   closedir(inputDir_dfd); // close Dir

   assert(!close(key_fd)); // close key file

}

благодаря.


person Eylon Saadon    schedule 30.10.2015    source источник
comment
Вы включили stdio.h?. Какой у вас код?   -  person Linus    schedule 30.10.2015
comment
Вероятно, в вашей командной строке отсутствует -lc для библиотеки C в конце.   -  person Jens Gustedt    schedule 30.10.2015
comment
Добавлен '-lc' для опций сборки в Clion, это не сработало. он компилируется на моей машине Kubuntu. Это только в Клионе.   -  person Eylon Saadon    schedule 30.10.2015
comment
@EylonSaadon Я предполагаю, что у вас есть glibc в вашей системе, верно?   -  person Linus    schedule 30.10.2015
comment
@ Линус не уверен, что такое «glibc». но в результате поиска я обнаружил, что MinGW не строится против glibc, а строится против msvcrt. Таким образом, вместо этого он использует libmsvcrtXX.a. /questions/6394512/standard-c-library-in-mingw   -  person Eylon Saadon    schedule 30.10.2015